java - Java 类名中的有效字符

标签 java class unicode naming-conventions invalid-characters

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/

相关文章:

apache-poi - 使用 java 管理 MS Excel 的工作表保护属性

java - 在 Java 中使用 Scanner 忽略字符

java - 使用一个类中的方法到另一个类中

java - 从 Windows 控制台中的 Java 代码问题打印出 unicode

java - 在 JavaFX 中为 Canvas 创建一个 "shadow"层?

java - JQuery 在 tomcat 中不工作

java - Eclipse 正在创建两个类文件

python - 通过类层次结构合并字典类属性

Python - 增加特定控制台输出的大小

unicode - 在 Dart 中处理字素簇