双语版Java程序设计
上QQ阅读APP看本书,新人免费读10天
设备和账号都新为新人

2.6 White Space

The first rule we present is a rule that does not result in any tokens or larger language structures. White space in Java refers to the space character (what you get when you type the space bar on the keyboard), the tab character (this is actually one character although it may appear as several spaces on your screen) and the new line character (what you get when you type the return or enter key on the keyboard). White space is used primarily to make the program look nice and also serves to separate adjacent, multi-character tokens that are not separated by any other punctuation(标点符号)and would otherwise be considered a single, longer token.

For example, white space is used to separate the words (tokens) public static void that we saw in example. In such situations, where one white space character is required, any number of white space characters can be used. We could have, for example, put each of the words public, static and void on separate lines or put lots of spaces between them like this:

public static void main(...

Except with String literals discussed below, any number of one or more adjacent white space characters (even mixing tab, space and newline) is the same as just one white space character as far as the structure and meaning of the program are concerned. Stated another way, if you can legally put in one space, you can put in as many spaces, tabs and newlines as you want. You cannot put white space in the middle of a keyword or identifier such as a variable or class name.

除了即将讨论的String字符外,就程序的结构和意义而言,一个或多个相邻的空格字符(即使混合的tab、空格和换行字符)等同于一个空格字符。