6.2. Names and Identifiers

name is used to refer to an entity declared in a program.

There are two forms of names: simple names and qualified names.

simple name is a single identifier.

qualified name consists of a name, a "." token, and an identifier.

In determining the meaning of a name (§6.5), the context in which the name appears is taken into account. The rules of §6.5 distinguish among contexts where a name must denote (refer to) a package (§6.5.3), a type (§6.5.5), a variable or value in an expression (§6.5.6), or a method (§6.5.7).

Packages and reference types have members which may be accessed by qualified names. As background for the discussion of qualified names and the determination of the meaning of names, see the descriptions of membership in §4.4§4.5.2§4.8§4.9§7.1§8.2§9.2, and §10.7.

Not all identifiers in a program are a part of a name. Identifiers are also used in the following situations:

  • In declarations (§6.1), where an identifier may occur to specify the name by which the declared entity will be known.

  • As labels in labeled statements (§14.7) and in break and continue statements (§14.15§14.16) that refer to statement labels.

  • In field access expressions (§15.11), where an identifier occurs after a "." token to indicate a member of an object that is the value of an expression or the keyword super that appears before the "." token

FieldAccess:
    Primary . Identifier
    super . Identifier
    ClassName . super . Identifier
  • In some method invocation expressions (§15.12), where an identifier may occur after a "." token and before a "(" token to indicate a method to be invoked for an object that is the value of an expression or the keyword super that appears before the "." token

MethodInvocation:
    MethodName ( ArgumentListopt )
    Primary . NonWildTypeArgumentsopt Identifier ( ArgumentListopt )
    super . NonWildTypeArgumentsopt Identifier ( ArgumentListopt )
    ClassName . super . NonWildTypeArgumentsopt Identifier ( ArgumentListopt )
    TypeName . NonWildTypeArguments Identifier ( ArgumentListopt )
  • In qualified class instance creation expressions (§15.9), where an identifier occurs immediately to the right of the leftmost new token to indicate a type that must be a member of the compile-time type of the primary expression preceding the "." preceding the leftmost new token.

ClassInstanceCreationExpression:
    new TypeArgumentsopt TypeDeclSpecifier TypeArgumentsOrDiamondopt
                                                            ( ArgumentListopt ) ClassBodyopt
    Primary . new TypeArgumentsopt Identifier TypeArgumentsOrDiamondopt
                                                            ( ArgumentListopt ) ClassBodyopt

TypeArgumentsOrDiamond:
    TypeArguments
    <> 

ArgumentList:
    Expression
    ArgumentList , Expression

  

Names are used to refer to entities declared in a program.

A declared entity (§6.1) is a

(1)package

(2)class type (normal or enum)

(3)interface type (normal or annotation type)

(4)member (class, interface, field, or method) of a reference type

(5)type parameter (of a class, interface, method or constructor)

(6)parameter (to a method, constructor, or exception handler),

(7)local variable

6.5. Determining the Meaning of a Name

The meaning of a name depends on the context in which it is used. The determination of the meaning of a name requires three steps:

  • First, context causes a name syntactically to fall into one of six categories: PackageName, TypeName, ExpressionName, MethodName, PackageOrTypeName, or AmbiguousName.

  • Second, a name that is initially classified by its context as an AmbiguousName or as a PackageOrTypeName is then reclassified to be a PackageName, TypeName, or ExpressionName.

  • Third, the resulting category then dictates the final determination of the meaning of the name (or a compile-time error if the name has no meaning).

PackageName:
    Identifier
    PackageName . Identifier

TypeName:
    Identifier
    PackageOrTypeName . Identifier

ExpressionName:
    Identifier
    AmbiguousName . Identifier

MethodName:
    Identifier
    AmbiguousName . Identifier

PackageOrTypeName:
    Identifier
    PackageOrTypeName . Identifier

AmbiguousName:
    Identifier
    AmbiguousName . Identifier

  

6.5.1. Syntactic Classification of a Name According to Context

1、A name is syntactically classified as a PackageName in these contexts:

(1)In a package declaration (§7.4)

PackageDeclaration:
    Annotationsopt package PackageName ;

(2)To the left of the "." in a qualified PackageName

2、A name is syntactically classified as a TypeName in these contexts:

(1)In a single-type-import declaration (§7.5.1)

SingleTypeImportDeclaration:
    import TypeName ;  

(2)To the left of the "." in a single-static-import declaration (§7.5.3)

SingleStaticImportDeclaration:
    import static TypeName . Identifier ;  

(3)To the left of the "." in a static-import-on-demand declaration (§7.5.4)

StaticImportOnDemandDeclaration:
    import static TypeName . * ;  

(4)To the left of the "<" in a parameterized type (§4.5)

(5)In a type argument list (§4.5.1) of a parameterized type

TypeArguments:
    < TypeArgumentList >

TypeArgumentList:
    TypeArgument
    TypeArgumentList , TypeArgument

TypeArgument:
    ReferenceType
    Wildcard

Wildcard:
    ? WildcardBoundsopt

WildcardBounds:
    extends ReferenceType
    super ReferenceType  

(6)In an explicit type argument list in a method or constructor invocation

(7)In an extends clause in a type variable declaration (§8.1.2)

(8)In an extends clause of a wildcard type argument (§4.5.1)

(9)In a super clause of a wildcard type argument (§4.5.1)

(10)In an extends clause in a class declaration (§8.1.4)

(11)In an implements clause in a class declaration (§8.1.5)

(12)In an extends clause in an interface declaration (§9.1.3)

(13)After the "@" sign in an annotation (§9.7)

(14)As a Type (or the part of a Type that remains after all毕竟,终究 brackets are deleted) in any of the following contexts:

  • As the result type of a method (§8.4§9.4)

  • As the type of a formal parameter of a method or constructor (§8.4.1§8.8.1§9.4)

  • As the type of an exception that can be thrown by a method or constructor (§8.4.6§8.8.5§9.4)

  • As the type of a local variable (§14.4)

  • As the type of an exception parameter in a catch clause of a try statement (§14.20)

  • As the type in a class literal (§15.8.2)

  • As the qualifying type of a qualified this expression (§15.8.4).

  • As the class type which is to be instantiated in an unqualified class instance creation expression (§15.9)

  • As the direct superclass or direct superinterface of an anonymous class (§15.9.5) which is to be instantiated in an unqualified class instance creation expression (§15.9)

  • As the element type of an array to be created in an array creation expression (§15.10)

  • As the qualifying type of field access using the keyword super (§15.11.2)

  • As the qualifying type of a method invocation using the keyword super (§15.12)

  • As the type mentioned in the cast operator of a cast expression (§15.16)

  • As the type that follows the instanceof relational operator (§15.20.2)

3、A name is syntactically classified as an ExpressionName in these contexts:

(1)As the qualifying expression in a qualified superclass constructor invocation (§8.8.7.1)

(2)As the qualifying expression in a qualified class instance creation expression (§15.9)

(3)As the array reference expression in an array access expression (§15.13)

(4)As a PostfixExpression (§15.14)

(5)As the left-hand operand of an assignment operator (§15.26)

4、A name is syntactically classified as a MethodName in these contexts:

(1)Before the "(" in a method invocation expression (§15.12)

(2)To the left of the "=" sign in an annotation's element value pair (§9.7)

5、A name is syntactically classified as a PackageOrTypeName in these contexts:

(1)To the left of the "." in a qualified TypeName

(2)In a type-import-on-demand declaration (§7.5.2)

6、A name is syntactically classified as an AmbiguousName in these contexts:

(1)To the left of the "." in a qualified ExpressionName

(2)To the left of the "." in a qualified MethodName

(3)To the left of the "." in a qualified AmbiguousName

(4)In the default value clause of an annotation type element declaration (§9.6)

(5)To the right of an "=" in an an element value pair (§9.7)

Chapter 6. Names的更多相关文章

  1. python爬取365好书中小说

    需要转载的小伙伴转载后请注明转载的地址 需要用到的库 from bs4 import BeautifulSoup import requests import time 365好书链接:http:// ...

  2. python爬取小说详解(一)

    整理思路: 首先观察我们要爬取的页面信息.如下:  自此我们获得信息有如下: ♦1.小说名称链接小说内容的一个url,url的形式是:http://www.365haoshu.com/Book/Cha ...

  3. Javascript——概述 && 继承 && 复用 && 私有成员 && 构造函数

    原文链接:A re-introduction to JavaScript (JS tutorial) Why a re-introduction? Because JavaScript is noto ...

  4. 关于protected在子类创建父类对象无法访问父类protected方法或成员

    子类(父类的外部包)中访问父类的protetcted属性或者方法,是不可以通过创建父类对象调用的.注意:此处不讨论同包下的父类子类,因为同包下所有类都可访问protected属性或者方法. 请参见Ja ...

  5. Clean Code – Chapter 2: Meaningful Names

    Use Intention-Revealing Names The name should tell you why it exists, what it does, and how it is us ...

  6. Structure And Representation Of MIB Object Names - SNMP Tutorial

    30.8 Structure And Representation Of MIB Object Names We said that ASN.1 specifies how to represent ...

  7. locations in main memory to be referenced by descriptive names rather than by numeric addresses

    Computer Science An Overview _J. Glenn Brookshear _11th Edition Chapter 6 Programming Languages As s ...

  8. Think Python - Chapter 17 - Classes and methods

    17.1 Object-oriented featuresPython is an object-oriented programming language, which means that it ...

  9. JavaScript- The Good Parts CHAPTER 2

    I know it well:I read it in the grammar long ago.—William Shakespeare, The Tragedy(悲剧:灾难:惨案) of Titu ...

随机推荐

  1. 企业搜索引擎开发之连接器connector(十九)

    连接器是基于http协议通过推模式(push)向数据接收服务端推送数据,即xmlfeed格式数据(xml格式),其发送数据接口命名为Pusher Pusher接口定义了与发送数据相关的方法 publi ...

  2. 软件工程:java实现wordcount基本功能

    github链接:https://github.com/Nancy0611/wc 一:项目相关要求 该项目能统计文本文件的字符数.单词数和行数.这个项目要求写一个命令行程序,模仿已有wc.exe 的功 ...

  3. (4)-optXXX方法的使用

    在JSONObject获取value有多种方法,如果key不存在的话,这些方法无一例外的都会抛出异常.如果在线环境抛出异常,就会使出现error页面,影响用户体验,针对这种情况最好是使用optXXX方 ...

  4. [leetcode] 9. Binary Tree Level Order Traversal

    跟第七题一样,把最后的输出顺序换一下就行... Given a binary tree, return the level order traversal of its nodes' values. ...

  5. web api 请求结果中页面显示的json字符串与json对象结果不一致

    我在前端调用这个api的时候也是百思不得其解,明明看到页面上的结果ID是不一样的,但是在js中使用的时候,却一直有重复ID的情况 后来才发现原来是long这个类型的原因,JavaScript中Numb ...

  6. stack和stack frame

    首先,我们先来了解下栈帧和栈的基本知识: 栈帧也常被称为“活动记录”(activation record),是编译器用来实现过程/函数调用的一种数据结构. 从逻辑上讲,栈帧就是一个函数执行的环境,包含 ...

  7. 用MVC5+EF6+WebApi 做一个小功能(三) 项目搭建

    一般一个项目开始之前都会有启动会,需求交底等等,其中会有一个环节,大讲特讲项目的意义,然后取一个高大上的项目名字,咱这是一个小功能谈不上项目,但是名字不能太小气了.好吧,就叫Trump吧.没有任何含义 ...

  8. winform textbox控件keydown、keypress、keyup简单介绍

    1.执行先后顺序: keydown-->keypress-->keyup 2.按键相关操作: 1)keydown和keyup参数类型KeyEventArgs(提供了KeyCode)实现形式 ...

  9. 打开win8及以上操作系统的系统已安装程序目录

    Windows 8 的“Metro 界面”里不能像XP和Win7那样,点击“开始”->“程序”,显示系统所有安装的程序,这个功能还是非常有用的,可以帮助我们快速查看系统已经安装的程序!我编写了这 ...

  10. 关于Mybatis 反向生成后 查询结果全部为null 解决办法

    今天遇到了一个问题,就是mybatis通过反向生成工具 生成的pojo类(实体类) xml文件 以及Mapper之后查询时结果为null 我写的代码怎么看都没有错 就是没有结果 后来在排除错误的时候发 ...