Java Reference
In-Depth Information
• If the second method is a generic method as described above, then A l <:
B l [ R 1 = A 1 ,..., R p = A p ] (1 ≤ l p ).
The above conditions are the only circumstances under which one method may be more
specific than another.
A method m 1 is strictly more specific than another method m 2 if and only if m 1 is more
specific than m 2 and m 2 is not more specific than m 1 .
A method is said to be maximally specific for a method invocation if it is accessible and ap-
plicable and there is no other method that is applicable and accessible that is strictly more
specific.
If there is exactly one maximally specific method, then that method is in fact the most spe-
cific method ; it is necessarily more specific than any other accessible method that is applic-
able. It is then subjected to some further compile-time checks as described in § 15.12.3 .
It is possible that no method is the most specific, because there are two or more methods
that are maximally specific. In this case:
• If all the maximally specific methods have override-equivalent (§ 8.4.2 ) signatures,
then:
♦ If exactly one of the maximally specific methods is not declared abstract , it is
the most specific method.
♦ Otherwise, if all the maximally specific methods are declared abstract , and the
signatures of all of the maximally specific methods have the same erasure
4.6 ) , then the most specific method is chosen arbitrarily among the subset of
the maximally specific methods that have the most specific return type.
However, the most specific method is considered to throw a checked exception
if and only if that exception or its erasure is declared in the throws clauses of
each of the maximally specific methods.
• Otherwise, we say that the method invocation is ambiguous , and a compile-time
error occurs.
15.12.2.6. Method Result and Throws Types
The result type of the chosen method is determined as follows:
• If the chosen method is declared with a return type of void , then the result is void .
• Otherwise, if unchecked conversion was necessary for the method to be applicable,
then the result type is the erasure (§ 4.6 ) of the method's declared return type.
Search WWH ::




Custom Search