Bug 81332 - [1.5][compiler] Is this a name clash?
Summary: [1.5][compiler] Is this a name clash?
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.1   Edit
Hardware: PC All
: P3 normal (vote)
Target Milestone: 3.1 M5   Edit
Assignee: Kent Johnson CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-12-15 16:50 EST by Kent Johnson CLA
Modified: 2005-02-16 06:34 EST (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Kent Johnson CLA 2004-12-15 16:50:46 EST
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.
Comment 1 Mikael Cluseau CLA 2004-12-15 16:58:51 EST
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 ?
Comment 2 Mikael Cluseau CLA 2004-12-15 17:02:45 EST
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.
Comment 3 Philipe Mulet CLA 2004-12-16 04:09:19 EST
Actually, Kent, should it diagnose a nameclash due to conflict with bridge
method from A ?
Comment 4 Kent Johnson CLA 2004-12-16 10:36:13 EST
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.
Comment 5 Kent Johnson CLA 2005-01-10 12:28:25 EST
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
Comment 6 Kent Johnson CLA 2005-02-01 11:51:04 EST
Reworked our name clash detection.

Added MethodVerify test034
Comment 7 David Audel CLA 2005-02-16 06:34:47 EST
Verified in I20050215-2300