Java Reference
In-Depth Information
parameters (either primitive or reference types) match the
corresponding arguments provided.
2. If no matches have been found, the match is attempted
again, but this time boxing conversions are considered, so
primitives can be passed for objects and vice-versa.
3. If no matches have been found, the match is attempted
again, but this time the possibility of a variable number of
arguments is considered, so now the number of arguments
might exceed the number of declared parameters.
3. If any method in the set has parameter types that are all as-
signable to the corresponding parameters of any other method in
the set, that other method is removed from the set because it
is a less specific method. For example, if the set has a method
that takes an Object parameter and another that takes a String
parameter, the Object method is removed because a String can
be assigned to an Object , and therefore the method that takes a
String is more specific. If you pass a String argument you want it
handled by the method that specializes in strings, not the general
one that works with any object.
4. If exactly one method remains, that method is the most specific
and will be invoked. If more than one method remains, and they
have different signatures, then the invocation is ambiguous and
the invoking code invalid because there is no most specific meth-
od. If all the remaining methods have the same signature then:
if all are abstract then one is chosen arbitrarily; otherwise if only
one is not abstract then it is chosen; otherwise the invocation is
again ambiguous and is invalid.
The exact details of the algorithm are quite complex, due mainly to the
possibility of generic types or methods being involvedsee Chapter 11 .
Interested readers should again consult The Java Language Specifica-
tion , Third Edition , for those details.
Once a method has been selected, that method determines the expected
return type and the possible checked exceptions of that method invoc-
 
Search WWH ::




Custom Search