Community
Participate
Working Groups
I200409140800 The second and third call to m(..) yield wrong errors. After erasure, there's no ambiguity, since the three methods m(..) are distinct. Maybe connected to bug 73970. public class X { static <E extends A> void m(E e) { System.out.println("A:"+e.getClass()); } static <E extends B> void m(E e) { System.out.println("B:"+e.getClass()); } static <E extends C> void m(E e) { System.out.println("C:"+e.getClass()); } public static void main(String[] args) { m(new A()); m(new B()); //error: "The method m(B) is ambiguous for the type X" m(new C()); //error: "The method m(C) is ambiguous for the type X" } } class A {} class B extends A {} class C extends A {} javac 1.5.0-beta3-b62 compiles it and prints: A:class q.A B:class q.B C:class q.C
Philippe - This is a bug in ParameterizedGenericMethodBinding computeCompatibleMethod() When the message send is m(new B()) and we substitute for the method: <E extends A> void m(E e) we create a ParameterizedGenericMethodBinding: m(B) instead of: m(A) So we get 2 ParameterizedGenericMethodBindings with B as their substituted parameter instead of one with A & one with B. Added MethodVerifyTest.test016()
Type inference is not meant to substitute parameters with their bounds, but rather with type inferred from argument types. In this case, both (A)m(E) and (B)m(E) are substitutable into: m(B), which causes the ambiguity in the end. I suspect the tiebreak should use original methods rather than substituted ones, or at least have original bounds play.
Tuned tiebreak. Added regression tests: GenericTypeTest#test425--426. Fixed
Verified in 200412140800