This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

primitive char and unicode value assignments  RSS feed

 
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
Marshal
Posts: 5565
712
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
Marshal
Posts: 5565
712
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
Sheriff
Posts: 16028
87
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
Boost this thread!