Java Reference
In-Depth Information
An implementation of the Java programming language must ensure, as part of linkage, that
the method m still exists in the type T . If this is not true, then a NoSuchMethodError (which is
a subclass of IncompatibleClassChangeError ) occurs.
If the invocation mode is interface , then the implementation must also check that the target
reference type still implements the specified interface. If the target reference type does not
still implement the interface, then an IncompatibleClassChangeError occurs.
The implementation must also ensure, during linkage, that the type T and the method m are
accessible:
• For the type T :
♦ If T is in the same package as C , then T is accessible.
♦ If T is in a different package than C , and T is public , then T is accessible.
♦ If T is in a different package than C , and T is protected , then T is accessible if
and only if C is a subclass of T .
• For the method m :
♦ If m is public , then m is accessible. (All members of interfaces are public 9.2 ).)
♦ If m is protected , then m is accessible if and only if either T is in the same pack-
age as C , or C is T or a subclass of T .
♦ If m has default (package) access, then m is accessible if and only if T is in the
same package as C .
♦ If m is private , then m is accessible if and only if C is T , or C encloses T , or T
encloses C , or T and C are both enclosed by a third class.
If either T or m is not accessible, then an IllegalAccessError occurs (§ 12.3 ) .
15.12.4.4. Locate Method to Invoke
The strategy for method lookup depends on the invocation mode.
If the invocation mode is static , no target reference is needed and overriding is not allowed.
Method m of class T is the one to be invoked.
Otherwise, an instance method is to be invoked and there is a target reference. If the target
reference is null , a NullPointerException is thrown at this point. Otherwise, the target reference
is said to refer to a target object and will be used as the value of the keyword this in the
invoked method. The other four possibilities for the invocation mode are then considered.
Search WWH ::




Custom Search