Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

Unicode identifier

 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi everybody !


is equivalent to

which is equivalent to


Try to do

and you will get an error.

Try this


and it compiles !

Can somebody explain it to me please ?


Cheers,

Adrian
 
Ranch Hand
Posts: 262
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi !!!

The unicode notation can not accept more or less than 4 digits.
char a='\u00061'; is not correct, because you have 5 digits.

char \u00012345='a'; will not compile. I guest you want to say that:
char \u00612345='a'; will compile.

Because the unicode of 'a' is 0061,
char \u00612345='a'; will be translate as: char a2345='a';

And a2345 is a valid identiier name.
 
Rancher
Posts: 43028
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator



and you will get an error.


It's not a valid Unicode character (which consist of 4 digits from 0-F each).



and it compiles !


No it doesn't, because the Unicode codepoint at 1 can not be the first character in an identifier. Something like "\u00612345" would compile, and would correspond to an identifier named "a2345" (which you can check by putting "System.out.println(a2345);" behind it.

The compiler performs a substitution of Unicode characters before the compilation. In the former case, you'd end with 2 characters, which can't be assigned to a char. In the latter case you end up with a valid identifier (a2345) if you use the sequence I suggested.
 
Adrian Sosialuk
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Guys - you are amazing !

Thanks a lot !
I would never have thought about it that way ....


Thanks !

Adrian
 
It is an experimental device that will make my mind that most powerful force on earth! More powerful than this tiny ad!
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic