Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is \u65549 a valid Java identifier?

I have these statements:

int \u65549 = 9;
System.out.println(\u65549);

This compiles perfectly. And outputs

9

But :

System.out.println(Character.isJavaIdentifierStart(\u65549));

outputs

false


I did some research on this topic. I read the documentation, and it says:

This method cannot handle supplementary characters. To support all Unicode characters, including supplementary characters, use the isJavaIdentifierStart(int) method.

Then I did this:

int x = \u65549;
System.out.println(Character.isJavaIdentifierStart(x));

But even this prints:

false

So, does this mean, that Java is confused over \u65549 being an identifier?

like image 945
dryairship Avatar asked Apr 04 '16 13:04

dryairship


2 Answers

int \u65549 = 9;
System.out.println(Character.isJavaIdentifierStart(\u65549));

Here, \u65549 is the name of a variable, that also happens to contain the value 9. It should (and does) do the same as if you wrote:

System.out.println(Character.isJavaIdentifierStart(9));

which prints false, since you can't have a Java identifier starting with a whitespace character (\u0009 is the codepoint for HORIZONTAL TAB, '\t').

like image 98
Andy Turner Avatar answered Oct 11 '22 06:10

Andy Turner


\u65549 is interpreted as the unicode character \u6554 , followed by the character 9.

This is a valid syntax in a String .

Other than that, \u65549 is not a valid unicode identifier. A String only takes the valid part (4 characters in the hexadecimal range) when it encounters a unicode prefix (\u), so it takes only the valid identifier part, and obtains a valid character .

like image 41
Arnaud Avatar answered Oct 11 '22 06:10

Arnaud