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:
.
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.
.
Identifier; then the name of the method is the Identifier and the class or interface to search is the declared type of the field named by the FieldName.
.
Identifier, then the name of the method is the Identifier and the class or interface to be searched is the type of the Primary expression.
super
.
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. A compile-time error occurs if such a method invocation occurs in an interface, or in the class Object
, or in a static
method, a static initializer, or the initializer for a static
variable. It follows that a method invocation of this form may appear only in a class other than Object
, and only in the body of an instance method, the body of a constructor, or an initializer for an instance variable.