Java 类名中的有效字符 [英] Valid characters in a Java class name

查看:24
本文介绍了Java 类名中的有效字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Java 类名中哪些字符是有效的?Java 类名还有哪些其他规则(例如,Java 类名不能以数字开头)?

What characters are valid in a Java class name? What other rules govern Java class names (for instance, Java class names cannot begin with a number)?

推荐答案

您几乎可以拥有任何字符,包括大多数 Unicode 字符!确切的定义在 Java 语言规范中在第 3.8 节:标识符下.

You can have almost any character, including most Unicode characters! The exact definition is in the Java Language Specification under section 3.8: Identifiers.

一个标识符Java字母Java数字的无限长度序列,其中第一个必须是Java信....

An identifier is an unlimited-length sequence of Java letters and Java digits, the first of which must be a Java letter. ...

可以从整个 Unicode 字符集中提取字母和数字,...这允许程序员在用他们的母语编写的程序中使用标识符.

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.

标识符不能与关键字(第 3.9 节)、布尔文本(第 3.10.3 节)或空文本(第 3.10.7 节)具有相同的拼写(Unicode 字符序列),否则会发生编译时错误.

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.

但是,请参阅这个问题,了解您是否应该这样做.

However, see this question for whether or not you should do that.

这篇关于Java 类名中的有效字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆