简体   繁体   English

Java标识符

[英]java identifiers

Everywhere is said that a Java identifier can start with all characters (but not digits) including $ and _ 到处都说Java标识符可以以包括$_所有字符(但不能是数字)开头。

but I noticed that methods like isJavaIdentifierStart returns true also for other chars like § , £ , etc 但是我注意到像isJavaIdentifierStart这样的方法对于§£等其他字符也返回true

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 : 如果isJavaIdentifierStart返回true,那么根据定义 ,它是一个有效的Java标识符起始字符,因为这是规范对其进行定义的方式

Identifier: 标识符:
IdentifierChars but not a Keyword or BooleanLiteral or NullLiteral IdentifierChars,但不是关键字,BooleanLiteral或NullLiteral
IdentifierChars: IdentifierChars:
JavaLetter JavaLetter
IdentifierChars JavaLetterOrDigit 标识符字符JavaLetterOrDigit
JavaLetter: JavaLetter:
any Unicode character that is a Java letter (see below) 任何Java字母的Unicode字符(请参见下文)
JavaLetterOrDigit: JavaLetterOrDigit:
any Unicode character that is a Java letter-or-digit (see below) Java字母或数字的任何Unicode字符(请参见下文)
... ...
A "Java letter" is a character for which the method Character.isJavaIdentifierStart(int) returns true . “ Java字母”是一个字符,其Character.isJavaIdentifierStart(int)方法返回true

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. 它为§返回false,因为它不是字母, Character.getType('§')不是Character.LETTER_NUMBER ,不是货币符号,也不是连接标点符号。

It is true for the two currency symbols, because that is a specific criterion. 这是两个货币符号的对,因为这是一个特定的标准。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM