简体   繁体   English

是所有名称标识符吗?

[英]Are all names identifiers?

In the Java Language Specification 6.2 Link 在Java语言规范6.2中的链接

Here is the following code example: 这是下面的代码示例:

class Test {
    public static void main(String[] args) {
        Class c = System.out.getClass();
        System.out.println(c.toString().length() +
                           args[0].length() + args.length);
    }
}

And it states: 它指出:

the identifiers Test, main, and the first occurrences of args and c are not names. 标识符Test,main和args和c的第一个匹配项不是名称。 Rather, they are used in declarations to specify the names of the declared entities. 而是在声明中使用它们来指定所声明实体的名称。 The names String, Class, System.out.getClass, System.out.println, c.toString, args, and args.length appear in the example. 名称String,Class,System.out.getClass,System.out.println,c.toString,args和args.length出现在示例中。

But are the names like Class and String also identifiers? 但是,像Class和String这样的名称也是标识符吗? What is an identifier exactly? 标识符到底是什么?

An identifier is a type of a token. 标识符是令牌的类型。 From the specification of the lexical structure of Java : Java词法结构的规范:

3.8. 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. 标识符是Java字母和Java数字的无限长度序列,其中第一个必须是Java字母。

 Identifier: IdentifierChars but not a Keyword or BooleanLiteral or NullLiteral IdentifierChars: JavaLetter IdentifierChars JavaLetterOrDigit JavaLetter: any Unicode character that is a Java letter (see below) JavaLetterOrDigit: any Unicode character that is a Java letter-or-digit (see below) 

A "Java letter" is a character for which the method Character.isJavaIdentifierStart(int) returns true. “ Java字母”是方法Character.isJavaIdentifierStart(int)返回true的字符。

A "Java letter-or-digit" is a character for which the method Character.isJavaIdentifierPart(int) returns true. “ Java字母或数字”是一个字符,Character.isJavaIdentifierPart(int)方法为其返回true。

The "Java letters" include uppercase and lowercase ASCII Latin letters AZ (\A-\Z), and az (\a-\z), and, for historical reasons, the ASCII underscore (_, or \_) and dollar sign ($, or \$). “ Java字母”包括大写和小写的ASCII拉丁字母AZ(\\ u0041- \\ u005a)和az(\\ u0061- \\ u007a),并且由于历史原因,ASCII下划线(_或\\ u005f)和美元符号($或\\ u0024)。 The $ character should be used only in mechanically generated source code or, rarely, to access pre-existing names on legacy systems. $字符仅应在机械生成的源代码中使用,或很少用于访问旧系统上的现有名称。

The "Java digits" include the ASCII digits 0-9 (\0-\9). “ Java数字”包括ASCII数字0-9(\\ u0030- \\ u0039)。

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. 字母和数字可能来自整个Unicode字符集,该字符集支持当今世界上使用的大多数书写脚本,包括中文,日文和韩文的大字体。 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. 标识符不能具有与关键字(§3.9),布尔文字(§3.10.3)或空文字(§3.10.7)相同的拼写(Unicode字符序列),否则会发生编译时错误。

This might answer your 2nd question: 这可能会回答您的第二个问题:

http://www.cafeaulait.org/course/week2/08.html http://www.cafeaulait.org/course/week2/08.html

Identifiers are the names of variables, methods, classes, packages and interfaces. 标识符是变量,方法,类,包和接口的名称。 Unlike literals they are not the things themselves, just ways of referring to them. 与文字不同,它们不是事物本身,而是引用它们的方式。

An identifier is a user defined symbol . 标识符是用户定义的符号

It allows the compiler to differentiate between bindings to objects of the same type in the symbol table. 它允许编译器在符号表中区分对相同类型对象的绑定。

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

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