File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

character literals

 
natarajan meghanathan
Ranch Hand
Posts: 130
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the problem with the following simple code. I get compile time error:
public class ADirtyOne
{
char a = '\u000a';
}

while
char a = '\u007a'; compiles properly.
TIA
 
bill bozeman
Ranch Hand
Posts: 1070
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This has been discussed before, so if you need more explanation, do a search for 'u\000a'.
Basically it is because what does 'u\000a' represent? It is the new line feed. So when the compiler goes through the code, the first thing it does is replace all the unicode with the literal meaning, so you replace 'u\000a' with a line feed. Then you get:
char a =
;
which won't compile.
Bill
 
Anshuman Acharya
Ranch Hand
Posts: 144
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the same goes for char = '\u000d'
 
Tualha Khan
Ranch Hand
Posts: 287
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I read in the JLS, that the unicode escape sequence based char literals are processed at the earliest. So that's why '\u000a' is processed immediately and the ; in the end is taken to the next line.
Bye,
Tualha Khan
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic