문제

이 질문은 아마도 C와 같은 여러 줄 주석이있는 다른 언어에도 동일하게 적용될 것입니다.내가 직면 한 문제는 다음과 같습니다.Eclipse에서 Java 코드로 작업 중이며 코드 블록을 주석 처리하고 싶었습니다.그러나 문자 시퀀스 "* /"를 포함하는 문자열이 있으며 Eclipse는 주석이 문자열 내부에 있더라도 거기에서 끝나야한다고 생각합니다.많은 오류가 발생하고 빌드에 실패합니다. 라코 디스

Java 사양이 내 여러 줄 주석에 대한 Eclipse의 해석과 일치합니까?Java 및 / 또는 Eclipse가 이런 일을 설명 할 것이라고 생각합니다.

도움이 되었습니까?

해결책

Eclipse가 맞습니다.주석 내부에는 해석 컨텍스트가 없습니다 (이스케이프 없음 등). JLS §3.7 을 참조하십시오.

다른 팁

Eclipse에서 주석 처리하려는 소스 코드 부분을 강조 표시하고 Ctrl + /를 사용하여 강조 표시된 섹션의 모든 행에 주석을 추가 할 수 있습니다. 행 시작 부분에 "//"를 표시합니다.

또는 선택 항목을 차단 주석 처리하려면 Ctrl + Shift + / 조합을 사용하십시오.선택한 블록 주석을 감지합니다.그러나이 작업을 취소하는 것은 한 줄 주석보다 어렵습니다.

예, 간단한 테스트를 위해 코드를 주석 처리하고 있습니다.코드를 다른 방식으로 주석 처리하여 필요한 것을 이미 테스트했습니다.Java 및 / 또는 Eclipse의 이상한 기능이 무엇인지 궁금했습니다.

A simple test shows Eclipse is correct:

public class Test {
  public static final void main(String[] args) throws Exception {
    String s = "This is the original string.";
    /* This is commented out.
    s = "This is the end of a comment: */ ";
    */
    System.out.println(s);
  }
}

This fails to compile with:

Test.java:5: unclosed string literal
    s = "This is the end of a comment: */ ";

I may be helpful to just do a "batch" multiline comment so that it comments each line with "//". It is Ctrl+"/" in Idea for commenting and uncommenting the selected lines, Eclipse should have a similar feature.

I often use only // for inline commments, and use /* */ only for commenting out large blocks the way you have.

A lot of developers will still use /* */ for inline comments, because that's what they're familiar with, but they all run into problems like this one, in C it didn't matter as much because you could #if 0 the stuff away.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top