Author
why java compiler compile comments?
Sukhadev Patil
Greenhorn
Joined: Apr 12, 2006
Posts: 12
niti_pat@yahoo.com public class cv { public static void main(String args[]) { // char lf = '\u000a' ; // char lf = '\u000d' ; } } where \u000a is unicode value of Newline. \u000d is unicode value of Carrige Return. after compile jvm prints following error. why java compiler compile comment? C:\cv.java:5: unclosed character literal // char lf = '\u000a' ; ^ C:\cv.java:6: unclosed character literal // char cr = '\u000d' ; ^ 2 errors Press any key to continue...
Christophe Verré
Sheriff
Joined: Nov 24, 2005
Posts: 14685
All unicode characters are actually translated before compilation, in the whole file, comments included. Your carriage returned is also translated, so your comment becomes : Before translation: // char lf = '\u000a'; After translation // char lf = ' '; This is why compilation fails.
[My Blog]
All roads lead to JavaRanch
Sukhadev Patil
Greenhorn
Joined: Apr 12, 2006
Posts: 12
i think newline character and Caridge retrun character makes it to check comment..but how ? pls. reply on this
Tony Morris
Ranch Hand
Joined: Sep 24, 2003
Posts: 1608
posted Apr 13, 2006 00:09:00
0
There is an explanation here: http://jqa.tmorris.net/GetQAndA.action?qids=5&showAnswers=true
Tony Morris
Java Q&A (FAQ, Trivia)
Christophe Verré
Sheriff
Joined: Nov 24, 2005
Posts: 14685
The same here: http://www.coderanch.com/t/403130/java/java/why-java-compiler-compile-comments Oops
subject: why java compiler compile comments?