HI All, Can any body tell me wats goin on in the following code..... with single line comment in action there is a compile time error, and with multiline comment there is no error -------------------- class A { // char c1 = '\u000d'; compile time error after using the comment.. // char c2 = '\u000a'; compile time error after using the comment.. char c4 = '\u0000'; char c3 = '\uface'; } -------------------------- and thi couse no compile time error class A { /* char c1 = '\u000d'; no error char c2 = '\u000a'; */ char c4 = '\u0000'; char c3 = '\uface'; } --------------------------------- and if in the above code i am writing '\u0d';and '\u0a'; in the first and second line, then any type of comment is not working.... can any body tell me why it is so..... Thanx in advance......
Hi, '\u000a' is a newline char and the code at compile time changes to
//char c2= ' \u000a';
this causes the error unclosed literal. This does not happen with your second code because compiler does not go through multiline comment as it does with the single line comment.
Originally posted by Amitkumar Dhama: and if in the above code i am writing '\u0d';and '\u0a'; in the first and second line, then any type of comment is not working.....
Unicode escape sequences have 4 digits after the "\u", not 2 digits, so '\u0d'; is gibberish to the compiler.
Thanx 4 repplying, but as compiler does not go through the multiline comment then why it is giving error in writing '\u0d'; inside multiline comment...
For the same reason that '\u000a' causes a problem in an end-of-line comment. The compiler reads in the entire text file and tries to parse it character by character, including comments. It interprets \u as an escape sequence prefix signifying that the next four characters will be hexadecimal digits such that \uXXXX is the Unicode sequence for a known character. The compiler will then regard that sequence as one character.
If you have \u0d'; anywhere in your .java text file, the compiler will try to interpret the Unicode character signified by the 4-digit hex number 0d'; which causes an error because 0d'; is not a valid 4-digit hex number. This occurs during the parsing of the text file, which includes comments.
After all the Unicode sequences and other characters have been read in, the compiler will fully parse the code, determining what's a comment and what's not.
SCJA 1.0 (98%), SCJP 1.4 (98%)
If I'd had more time, I would have written a shorter letter. -T.S. Eliot such a short, tiny ad:
a bit of art, as a gift, that will fit in a stocking