Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
621 views
in Technique[技术] by (71.8m points)

unicode - Error due to content in a legal Comment in Java

On this coderanch link, I found that the following comment will give compiler error :-

// Compiler Error due to this Unicode char 'u000a'

Reason being, the Unicode sequence is directly replaced by the actual character it corresponds to. Since 'u000a' corresponds to newLine character, a newLine is placed at the place where 'u000a' is found.

My question is that, "Is there any other way of having Compilation Error due to a comment?"

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

"The compiler not only translates Unicode escapes into the characters they represent before it parses a program into tokens [...], but it does so before discarding comments and white space [JLS 3.2]." Java? Puzzlers: Traps, Pitfalls, and Corner Cases By Joshua Bloch, Neal Gafter.

And the next lines are valid Java code:

u0070u0075u0062u006cu0069u0063u0020u0020u0020u0020
u0063u006cu0061u0073u0073u0020u0055u0067u006cu0079
u007bu0070u0075u0062u006cu0069u0063u0020u0020u0020
u0020u0020u0020u0020u0073u0074u0061u0074u0069u0063
u0076u006fu0069u0064u0020u006du0061u0069u006eu0028
u0053u0074u0072u0069u006eu0067u005bu005du0020u0020
u0020u0020u0020u0020u0061u0072u0067u0073u0029u007b
u0053u0079u0073u0074u0065u006du002eu006fu0075u0074
u002eu0070u0072u0069u006eu0074u006cu006eu0028u0020
u0022u0048u0065u006cu006cu006fu0020u0077u0022u002b
u0022u006fu0072u006cu0064u0022u0029u003bu007du007d

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...