This week's book giveaway is in the General Computing forum. We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line! See this thread for details.
The above code doesn't compile it throws 2 errors, why is that if that's not enough take this class a { /*char a='\u000a';*/ }
this code ecompiles perfectly without any poblems anybody pls explain this Thanx aNiL
anilkuj
Greenhorn
Joined: Sep 18, 2000
Posts: 22
posted
0
hi! sunitha Then how does this compile? class a { //char a='\u0009'; } BTW my question actually was why it is checking the syntax even thoudgh i comment it with // but its not doing so for /* and */ type of comment. Thanx aNiL
Please read the following from JLS. Hope this answers your question:
Because Unicode escapes are processed very early, it is not correct to write '\u000a' for a character literal whose value is linefeed (LF); the Unicode escape \u000a is transformed into an actual linefeed in translation step 1 (�3.3) and the linefeed becomes a LineTerminator in step 2 (�3.4), and so the character literal is not valid in step 3. Instead, one should use the escape sequence '\n' (�3.10.6). Similarly, it is not correct to write '\u000d' for a character literal whose value is carriage return (CR). Instead, use '\r'.
I think it is something to do with Escape seq Try this - this works- i have removed the '\' char class a { //char a='u000a'; } This compiles fine But i too dont understand why /* */ works without any problem Is this a Bug in java Experts, JGurus Wakeup !!
vidhya Ramachandran already explained it The line: //char a='\u000a'; when read by javac into a String, has the unicode translation applied resulting in a line feed (a line terminator) so you end up with a split line: //char a= ; The other example /*char a='\u000a';*/ turns into /*char a= ;*/ which is a perfectly valid two line comment. Bill
Hi William , Ok the first part was clear but i am still not able to understand how the compiler is able at accept the same char. literal inside /* and */. Thanx aNiL
anilkuj
Greenhorn
Joined: Sep 18, 2000
Posts: 22
posted
0
Hi william yes i got it i understood i thought over it after i posted the reply. Thanx a lot. aNiL