Java 类名中哪些字符是有效的? Java 类名还有哪些其他规则(例如,Java 类名不能以数字开头)?
最佳答案
您几乎可以使用任何字符,包括大多数 Unicode 字符!确切的定义在 the Java Language Specification under section 3.8: Identifiers .
An identifier is an unlimited-length sequence of Java letters and Java digits, the first of which must be a Java letter. ...
Letters and digits may be drawn from the entire Unicode character set, ... This allows programmers to use identifiers in their programs that are written in their native languages.
An identifier cannot have the same spelling (Unicode character sequence) as a keyword (§3.9), boolean literal (§3.10.3), or the null literal (§3.10.7), or a compile-time error occurs.
但是,请参阅 this question你是否应该这样做。
关于java - Java 类名中的有效字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65475/