Yes, it is legal according to the JLS and according to the javac compiler. The '\u0061' is equivalent to 'a', and this replacement occurs before any other lexical parsing. So the line should be equivalent to
char a = 'a';
Evidently the Eclipse developers did not anticipate that anyone would ever try to use unicode escapes in a keyword, of all things. So technically this is a bug in Eclipse. (And it looks like IntelliJ has a similar problem.) But, why does it matter? Why not simply write 'char' as 'char' rather than ch\u0061r'? Seems like a bug with a simple workaround.
"I'm not back." - Bill Harding, Twister
Joined: Jan 01, 2007
most be fixed in 3.2.2 then
Joined: Sep 17, 2006
it cud be a bug. im using eclipse 3.2.1. though its beyond me why is it working on my neighbour's machine when he is using the same version. jim did you try it in your machine.
Just a thought: is there some sort of file encoding setting in the IDE that may be wrong? Probably the file is not being treated as a unicode file, which is why it doesn't work for you and works for others.
Aside from that, I'm just as confused as everyone else as to why you would want to write it like that.
Joined: Dec 30, 2011
Campbell Ritchie wrote:Are you sure it’s your back you are scratching?
For ascii characters it doesn't make sense. Most programs are written in just ascii anyway.
However, sometimes it can be useful to include non-ascii in a program that's written in an ascii source file. This is normally the case if you want to include a unicode character into a String, but you can also use it for special characters in identifiers. The only situation I can think of where the latter would be useful is when you have to interact with third party libraries written in another language.
The \uxxxx combinations are converted to unicode characters before the parser builds the expression tree, so this is why you can also use it for keywords. You should avoid doing this though.