本帖最后由 zzmxhm 于 2014-4-3 21:54 编辑
Java 规范中是这样定义标识符的:An identifier is an unlimited-length sequence of Java letters and Java digits, the first of which must be a Java letter.
即标识符可以由 Java letter 和 Java digit 组成,并且以 Java letter 开头。而 Java letter 是这样定义的:
A "Java letter" is a character for which the method Character.isJavaIdentifierStart(int) returns true.
因此中文字符也属于 Java letter,故可以作为标识符的一部分。特别的,Java 规范中还专门指出标识符允许使用 CJK 字符:
Letters and digits may be drawn from the entire Unicode character set, which supports most writing scripts in use in the world today, including the large sets for Chinese, Japanese, and Korean. This allows programmers to use identifiers in their programs that are written in their native languages.
但使用中文字符肯定是有弊端的,首先就是不方便。其次,Java 内建了对 Unicode 字符集的支持,因此在 Java 中使用中文没有大问题。但有很多其它软件或系统没有原生的 Unicode 字符集支持机制,会使得依赖于中文的 Java 程序在和其它软件交互时出现问题。
|