문제

I'm reading into the Java Language Specifications (se8), and I came across this..

Lines are terminated by the ASCII characters CR, or LF, or CR LF. The two characters CR immediately followed by LF are counted as one line terminator, not two.

A line terminator specifies the termination of the // form of a comment (§3.7).

http://docs.oracle.com/javase/specs/jls/se8/html/jls-3.html#jls-3.4

I don't understand what it means, and there aren't any examples of how it works. Based off context, I'm guessing a line terminator would be the end of a comment, so for

/*
  *
  */

The line terminator would be */ (please correct me if I'm wrong)

I don't understand how line terminators would apply to // comments.

EDIT: So I guess I wasn't going crazy, \n \r are considered line terminators, which was my very first guess. What really confuses me is why they refer to comments when talking about this, when usually (from what Ive seen), they're used for Strings.

도움이 되었습니까?

해결책 2

Read this: http://en.wikipedia.org/wiki/Newline

It's the ASCII encoded character sequence that signifies the end of a line, depending on your platform.

For instance, ASCII characters CR (carriage return), LF (line feed), or both CRLF (Carriage Return, immediately followed by line feed) are used to denote the end of a line of text. On most UNIX platforms, only a single CR character is used, while on DOS based platforms, usually the sequence CRLF is used to denote the end of line, and as such, that sequence is usually interpreted as "one terminator" because they must be in that order.

To address the specific question (based on comment feedback): This has nothing to do with comments, from your perspective as the user. It matters to the parser of your Java source code, in that, when a line is read, it expects the appropriate line terminator to be there. You effectively accomplish this by pressing "Enter" to insert a new line. The encoding of the file, your text editor, and platform all need to be in agreement which specific character; CR, LF, or CRLF are actually inserted when you add a new line.

다른 팁

A line terminator is an actual ascii character which is invisible to humans but important to computers. The line terminator character tells the computer where to start a new line. We tell computers to "print" terminators when we want new lines. For example, in java, instead of doing

System.out.println("Hello World");

You could do

System.out.print("Hello World\n");

Where the "\n" represents the line terminator or "new line".

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