15.12. Method Invocation Expressions
-
15.12.1. Compile-Time Step 1: Determine Class or Interface to Search
15.12.2. Compile-Time Step 2: Determine Method Signature
-
-
15.12.2.1. Identify Potentially Applicable Methods
15.12.2.2. Phase 1: Identify Matching Arity Methods Applicable by Subtyping
15.12.2.3. Phase 2: Identify Matching Arity Methods Applicable by Method Invocation Conversion
15.12.2.4. Phase 3: Identify Applicable Variable Arity Methods
15.12.2.5. Choosing the Most Specific Method
15.12.2.6. Method Result and Throws Types
15.12.2.7. Inferring Type Arguments Based on Actual Arguments
15.12.2.8. Inferring Unresolved Type Arguments
15.12.3. Compile-Time Step 3: Is the Chosen Method Appropriate?
15.12.4. Run-Time Evaluation of Method Invocation
方法调用的形式主要有5种:
MethodInvocation:
MethodName (
ArgumentListopt )
Primary .
NonWildTypeArgumentsopt Identifier (
ArgumentListopt )
super
.
NonWildTypeArgumentsopt Identifier (
ArgumentListopt )
ClassName .
super
.
NonWildTypeArgumentsopt Identifier (
ArgumentListopt )
TypeName .
NonWildTypeArguments Identifier (
ArgumentListopt )
举个例子如下:
class A{
public void test(){}
}
public class TestMethodInvocation extends A{
public void m1(){}
public static void m2(){}
public void test(){
m1();
A a = new TestMethodInvocation();
a.test();
super.test();
TestMethodInvocation.m2();
}
class C{
public void m(){
// It is a compile-time error if C is not a lexically enclosing class of the current class.
TestMethodInvocation.super.test();
}
}
}