Prev: Axis2 vs. multirefs
Next: MYFaces in tomcat 5.x
From: dimakura on 19 Feb 2007 09:33 i found in the web-search why i can not use //////////////////// char c = '\u000a' //////////////////// but i can not find why i can not use //////////////////// // char c = '\u000a' //////////////////// is it because '\u000a' is equivivalent to \n and this type is comment is a single-line? thanks, dimitri
From: Gordon Beaton on 19 Feb 2007 10:02 On 19 Feb 2007 06:33:32 -0800, dimakura wrote: > is it because '\u000a' is equivivalent to \n and this type is > comment is a single-line? Yes. Read section 3.2 of the JLS, which describes translation of the input to the compiler. The unicode escape sequences are translated into their corresponding unicode characters, *then* the resulting sequence of characters is tokenized. So when you escape a line feed as you've done, you are essentially writing this (illegal) code: char c = ' ' i.e. the closing quote ends up on the following line. Similarly, commenting the line results in this invalid sequence: // char c = ' ' /gordon -- [ don't email me support questions or followups ] g o r d o n + n e w s @ b a l d e r 1 3 . s e
From: Oliver Wong on 19 Feb 2007 09:52 "dimakura" <dimitri.kurashvili(a)telasi.ge> wrote in message news:1171895612.075409.27320(a)k78g2000cwa.googlegroups.com... >i found in the web-search why i can not use > > //////////////////// > > char c = '\u000a' > > //////////////////// > > but i can not find why i can not use > > //////////////////// > > // char c = '\u000a' > > //////////////////// > > is it because '\u000a' is equivivalent to \n and this type is comment > is a single-line? The process of converting unicode escape sequences to characters happens somewhere between reading the source file, and then parsing source file for compilation. So javac will read in the file, and thus get: //////////////////// // char c = '\u000a' //////////////////// Then it will convert unicode escape sequences to their equivalent characters and get: //////////////////// // char c = ' ' //////////////////// And then it will try to compile this code, and it'll fail with some sort of error like "Not expecting apostrophe here". - Oliver
From: Chris Uppal on 19 Feb 2007 10:03 dimakura wrote: > but i can not find why i can not use > // char c = '\u000a' > is it because '\u000a' is equivivalent to \n and this type is comment > is a single-line? Yes, exactly right. -- chris
From: Andreas Leitgeb on 19 Feb 2007 14:10
Chris Uppal <chris.uppal(a)metagnostic.REMOVE-THIS.org> wrote: > dimakura wrote: >> but i can not find why i can not use >> // char c = '\u000a' >> is it because '\u000a' is equivivalent to \n and this type is comment >> is a single-line? > Yes, exactly right. And to test yourself, whether you've really understood, predict what the compiler will say to that: // char c = '\u000a//' // :-) |