Java Reference
In-Depth Information
of the arguments used in the method invocation. This is clarified
in an example below.
5. The search for the maximally specific method is not based on
"same or different signature" but rather on whether the signa-
tures are override-equivalent (as previously described) or not.
6. If the maximally specific method is a generic method, then the
type of the method invocation expression is the inferred return
type of that generic method as determined by the type inference
applied as in point 2 above.
For example, consider these two overloads of a method m :
void m(String key, Object val) {
// ...
}
<S, T extends Number> void m(S key, T val) {
// ...
}
Now consider this invocation of m :
m("hello", "world");
Both forms of m are potentially applicable because they have the right
name and the right number of parameters. Both arguments are refer-
ence types and neither method has a variable number of parameters,
so only phase 1 for finding the applicable methods will occur. First, the
type arguments of the generic method must be inferred. Attempting to
do so, however, requires that String extend Number ; it does not, so the
generic form is not applicable. The non-generic form is applicable be-
cause it matches in the first argument type exactly, and in the second
a String can be assigned to an Object . Since there is only one applicable
method, it is selected.
 
Search WWH ::




Custom Search