Everywhere is said that a Java identifier can start with all characters (but not digits) including $
and _
but I noticed that methods like isJavaIdentifierStart
returns true also for other chars like §
, £
, €
etc
Is however correct starting an identifier with there characters?
If isJavaIdentifierStart
returns true for it, then by definition , it's a valid Java identifier starting character, because that's how the specification defines it :
Identifier:
IdentifierChars but not a Keyword or BooleanLiteral or NullLiteral
IdentifierChars:
JavaLetter
IdentifierChars JavaLetterOrDigit
JavaLetter:
any Unicode character that is a Java letter (see below)
JavaLetterOrDigit:
any Unicode character that is a Java letter-or-digit (see below)
...
A "Java letter" is a character for which the methodCharacter.isJavaIdentifierStart(int)
returnstrue
.
The method means what it says.
It returns false for §
, because it's not a letter, Character.getType('§')
is not Character.LETTER_NUMBER
, it's not a currency symbol, and it's not a connecting punctuation character.
It is true for the two currency symbols, because that is a specific criterion.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.