Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

This is really amazing ...........pls check out this

 
anilkuj
Greenhorn
Posts: 22
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
class a
{
//char a='\u000a';
}

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
Posts: 22
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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


 
vidhya Ramachandran
Greenhorn
Posts: 13
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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'.
 
Rahul
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 !!
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13047
6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
anilkuj
Greenhorn
Posts: 22
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 22
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi william
yes i got it i understood i thought over it after i posted the reply. Thanx a lot.
aNiL
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic