• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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: 43081
77
  • 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
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic