Java Reference
In-Depth Information
If the invocation mode is nonvirtual , overriding is not allowed. Method m of class T is the
one to be invoked.
Otherwise, if the invocation mode is virtual , and T and m jointly indicate a signature
polymorphic method (§ 15.12.3 ) , then the target object is an instance of
java.lang.invoke.MethodHandle . The method handle encapsulates a type which is matched
against the information associated with the method invocation at compile time (§ 15.12.3 ) .
Details of this matching are given in The Java Virtual Machine Specification, Java SE 7
Edition and the Java SE platform API. If matching succeeds, the target method encap-
sulated by the method handle is directly and immediately invoked, and the procedure in
§ 15.12.4.5 is not executed .
Otherwise, the invocation mode is interface , virtual , or super , and overriding may occur. A
dynamic method lookup is used. The dynamic lookup process starts from a class S , determ-
ined as follows:
• If the invocation mode is interface or virtual , then S is initially the actual run-time
class R of the target object.
This is true even if the target object is an array instance. (Note that for invoc-
ation mode interface , R necessarily implements T ; for invocation mode virtual , R
is necessarily either T or a subclass of T .)
• If the invocation mode is super , then S is initially the qualifying type (§ 13.1 ) of the
method invocation.
The dynamic method lookup uses the following procedure to search class S , and then the
superclasses of class S , as necessary, for method m .
Let X be the compile-time type of the target reference of the method invocation. Then:
1. If class S contains a declaration for a non- abstract method named m with the same
descriptor (same number of parameters, the same parameter types, and the same
return type) required by the method invocation as determined at compile time
15.12.3 ) , then:
• If the invocation mode is super or interface , then this is the method to be invoked,
and the procedure terminates.
• If the invocation mode is virtual , and the declaration in S overrides (§ 8.4.8.1 )
X . m , then the method declared in S is the method to be invoked, and the proced-
ure terminates.
• If the invocation mode is virtual , and the declaration in S does not override X . m ,
and moreover X . m is declared abstract , then an AbstractMethodError is thrown.
Search WWH ::




Custom Search