Community
Participate
Working Groups
See bug 80765 If B.test(String) is not a name class with I.test(E) in this case: interface I<E extends Comparable<E>> { public void test(E element); } class A implements I<Integer> { public void test(Integer i) {} } class B extends A { public void test(String i) {} } Why is B.test(Comparable) if B is defined as: class B extends A { public void test(Comparable c) {} } B should be allowed to implement any 'new' test method since A implements I.test correctly.
I agree with Kent in his case, but my case it most likely the following one : interface I<E extends Comparable<E>> { public >>E<< test(E element); } class A implements I<Integer> { public >>Integer<< test(Integer i) {} } class B extends A { public >>Comparable<< test(>>Comparable<< i) {} } Isn't there an obvious name clash because of the return type ?
I would also that it is only generics-related, because in Java 1.4 you can't even have this : class A { public Comparable test(Comparable c); } class B { public Integer test(Integer i); } ... and only because it is a kind of generics.
Actually, Kent, should it diagnose a nameclash due to conflict with bridge method from A ?
Mikael - return types are not considered when looking for name clashes, since its only the parameters which decide the correct method to dispatch. Philippe - I have yet to see any case when the bridge method was used for comparison.
Another case that causes a name clash with javac: class E extends F<E> { public int compareTo(Object o) { return 0; } // name clash: compareTo(java.lang.Object) in E and compareTo(U) in I<E> // have the same erasure, yet neither overrides the other } abstract class F<T extends F<T>> implements I<T>{ public final int compareTo(T o) { return 0; } } interface I<U>{ int compareTo(U o); } But since E inherits from F that provides a valid implementation of compareTo (F) and a bridge method for compareTo(Object), I don't see why E.compareTo (Object) would cause a name clash. This is a simplified case from bug 80626
Reworked our name clash detection. Added MethodVerify test034
Verified in I20050215-2300