Java Reference
In-Depth Information
< Day Day Up >
1. Lexical Issues
This section concerns the lexical structure of Java programs: the tokens that make up programs and
the characters that make up tokens.
1.1. The letter el looks like the digit 1 in many fonts
Prescription: In long literals, always use a capital el ( L ), never a lowercase el ( l ). Do not use a lone
el ( l ) as a variable name.
References: Puzzle 4 .
1.2. Negative hex literals appear positive
Prescription: Avoid mixed-type computation; use long literals instead of int literals where
appropriate.
References: Puzzle 5 ; [JLS 3.10.1].
1.3. Octal literals look like decimal literals
Prescription: Avoid octal literals. If you must use them, comment all uses to make your intentions
clear.
References: Puzzle 59 ; [JLS 3.10.1].
1.4. Unicode escapes for ASCII characters are confusing
Prescription: Don't use Unicode escapes for ASCII characters. Where possible, use ASCII
character directly. In string literals and character literals, prefer escape sequences to Unicode
escapes.
References: Puzzles 14 , 16 , and 17 ; [JLS 3.2, 3.3].
1.5. Backslashes must be escaped, even in comments
Prescription: If you are writing a system that generates Java source code, escape backslashes in
generated character literals, string literals, and comments. Windows filenames are a common
source of trouble.
References: Puzzles 15 and 16 ; [JLS 3.3].
 
 
Search WWH ::




Custom Search