Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
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 and the class or interface to search is the one whose declaration contains the method invocation.
- 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 onlystaticmethods and interfaces have nostaticmethods. - In all other cases, the qualified name has the form FieldName
.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.
- If the form is Primary
.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. - If the form is
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 classObject, or in astaticmethod, a static initializer, or the initializer for astaticvariable. It follows that a method invocation of this form may appear only in a class other thanObject, and only in the body of an instance method, the body of a constructor, or an initializer for an instance variable.