Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Reg. Unicode escape literals

 
Angela Narain
Ranch Hand
Posts: 327
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For Unicode escape literals

Is that when we use then as literals value for assigning
to a character we cannot use their hexadecimal equivalent.
For eg:
char c = '\u000a' gives compile error.
so we have to use
char c = '\b';
Pls. correct if wrong and explain to me.
 
Valentin Crettaz
Gold Digger
Sheriff
Posts: 7610
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JLS 3.2 explains very well that topic...
but char c = '\u000a'; is not allowed because when compiled the line would look like this:
char c = '
'; //note the line break
Val
 
Jane Griscti
Ranch Hand
Posts: 3141
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just to further Val's post, you cannot use '\u000A' or '\u000D' in a String literal or in single-line comments.
One of the first things the compiler does is evaulate Unicode literals. The above are intrepeted literally as 'newline' and 'carriage return'. They will break your code.
Always use '\n' and '\r'
------------------
Jane Griscti
Sun Certified Programmer for the Java� 2 Platform
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic