Duplicate :
|
|
Relates :
|
|
Relates :
|
|
Relates :
|
|
Relates :
|
|
Relates :
|
JLS 15.12.2.5 fails to specify the behavior of the following test case: class Foo<T> { void m(Integer arg) {} void m(T arg) {} } void m1(Foo<Integer> f1, Integer i) { f1.m(i); } Class type Foo<Integer> has two methods with the same signature. Of course, neither is more specific than the other. Clearly, there should be an ambiguity error. The behavior in such cases is outlined as follows: 1) If all the maximally specific methods have override-equivalent signatures, then: a) If exactly one of the maximally specific methods is not declared 'abstract', ... b) Otherwise, if all the maximally specific methods are declared 'abstract', and the signatures of all of the maximally specific methods have the same erasure, ... 2) Otherwise, we say the method invocation is ambiguous, and a compile-time error occurs. There is no case 1c, for when neither 1a nor 1b are true. As an aside, I think "the signatures of all of the maximally specific methods have the same erasure" is redundant, per 1. That is "all the maximally specific methods have override-equivalent signatures" implies "the signatures of all of the maximally specific methods have the same erasure"
|