Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

primitive char and unicode value assignments

 
Abimaran Kugathasan
Ranch Hand
Posts: 2066
Clojure IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


What is wrong here? I couldn't find out it! Thanks Advanced!


 
Devaka Cooray
ExamLab Creator
Marshal
Pie
Posts: 4317
233
Chrome Eclipse IDE Google App Engine IntelliJ IDE jQuery Postgres Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The character \u000A is something similar to a new line. In other words, your code gives a compile time error because of the same reason of why the following code is wrong:
 
Kamil Wojcik
Ranch Hand
Posts: 78
Eclipse IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Abimaran, You can try also something like this
 
Abimaran Kugathasan
Ranch Hand
Posts: 2066
Clojure IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kamil Wojcik wrote:Abimaran, You can try also something like this


I couldn't understand this! Thanks Devaka Cooray
 
Devaka Cooray
ExamLab Creator
Marshal
Pie
Posts: 4317
233
Chrome Eclipse IDE Google App Engine IntelliJ IDE jQuery Postgres Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Abimaran Kugathasan wrote:I couldn't understand this!


Have a look at the commented line. Since \u000A represents a new line, it is equivalent to the following:

Now, the second statement is not commented and thus it gets executed.
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15214
36
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The thing to be aware about here is that Unicode escapes such as \u000a are processed as the very first step in the compiler, before the compiler really looks at your code. The Unicode-escaped codes are replaced by their real characters, and \u000a is ofcourse a newline character.

Because of how this works, you cannot use Unicode escapes as a general way to include special characters in your source code (that's not what they are meant for).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic