Compile-Time Step 1: Determine Class or Interface to Search

15.12.1 Compile-Time Step 1: Determine Class or Interface to Search

The first step in processing a method invocation at compile time is to figure out the name of the method to be invoked and which class or interface to check for definitions of methods of that name. There are several cases to consider, depending on the form that precedes the left parenthesis, as follows.

• If the form is MethodName, then there are three subcases: ◆ If it is a simple name, that is, just an Identifier, then the name of the method

is the Identifier. If the Identifier appears within the scope (§6.3) of a visible method declaration

with that name, then: ❖ If there is an enclosing type declaration of which that method is a member,

be the innermost such type declaration. The class or interface to search is T .

let T

❖ Otherwise, the visible method declaration may be in scope due to one or more single-static-import (§7.5.3) or static-import-on-demand (§7.5.4)

declarations. There is no class or interface to search, as the method to be invoked is determined later (§15.12.2).

◆ If it is a qualified name of the form TypeName . Identifier, then the name of the method is the Identifier and the class to search is the one named by the

TypeName. If TypeName is the name of an interface rather than a class, then a compile-time

error occurs, because this form can invoke only static methods and interfaces have no static methods.

◆ In all other cases, the qualified name has the form FieldName . Identifier. The name of the method is the Identifier and the class or interface to search

is the declared type T of the field named by the FieldName, if T is a class or interface type, or the upper bound of T if T is a type variable.

• If the form is Primary . NonWildTypeArguments opt Identifier, then the name of the method is the Identifier.

EXPRESSIONS Compile-Time Step 2: Determine Method Signature 15.12.2

Let T be the type of the Primary expression. The class or interface to be searched is T if T is a class or interface type, or the upper bound of T if T is a type variable.

It is a compile-time error if T is not a reference type. • If the form is super . NonWildTypeArguments opt Identifier, then the name of the

method is the Identifier and the class to be searched is the superclass of the class whose declaration contains the method invocation.

Let T

be the type declaration immediately enclosing the method invocation. It is

a compile-time error if T is the class Object or T is an interface. • If the form is ClassName . super . NonWildTypeArguments opt Identifier, then

the name of the method is the Identifier and the class to be searched is the

superclass of the class C denoted by ClassName.

It is a compile-time error if C is not a lexically enclosing class of the current class.

It is a compile-time error if C is the class Object .

Let T

be the type declaration immediately enclosing the method invocation. It is

a compile-time error if T is the class Object or T is an interface. • If the form is TypeName . NonWildTypeArguments Identifier, then the name of

the method is the Identifier and the class to be searched is the class C denoted by TypeName.

If TypeName is the name of an interface rather than a class, then a compile-time error occurs, because this form can invoke only static methods and interfaces have no static methods.