Bug 202858 - [compiler] Confusing compilation errors when using generic types
Summary: [compiler] Confusing compilation errors when using generic types
Status: VERIFIED WORKSFORME
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.3   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.4 M2   Edit
Assignee: Kent Johnson CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-09-10 18:15 EDT by Simon Archer CLA
Modified: 2007-09-18 05:46 EDT (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 Simon Archer CLA 2007-09-10 18:15:00 EDT
Consider the following interface that employs the generic type T:

  public interface MyInterface<T> {
    public void method1(T t);
    public void method2(T t);
  }

And now consider the following implementation of this iterface, which also employs the generic type T:

  public class MyClass<T> implements MyInterface<T> {
    public void method1(T t) {
        //...
    }

    public void method2(T t) {
        //...
    }
  }

This all compiles fine.  But, introducing a bug into MyInterface<T>, results in very confusing compilation errors in both MyInterface<T> and, strangely enough, MyClass<T>.  Changing MyInterface<T> to:

  public interface MyInterface<T> {
    public void method1(T t);
    public void method2(T t);  
    public void method2(T t);   // DOES NOT COMPILE: Duplicate method
  }

results in the following error against both duplicate method2(T) methods:

  "Method method2(T) has the same erasure method2(Object) as another method
  in type MyInterface<T>"

This, of course is correct, be it rather cryptic.  I'd rather see the error:

  "Duplicate method method2(T) in type MyInterface<T>"

But that's not the worst of it.  Look at the class MyClass<T> you'll see the following errors, both of which are COMPLETELY UNRELATED to the duplicate method2(T) method:

  "Name clash: The method method1(T) of type MyClass<T> has the same erasure
  as method1(Object) of type MyInterface<T> but does not override it"

  "The type MyClass<T> must implement the inherited abstract method
  MyInterface<T>.method1(Object)"


This makes for some seriously difficult problems to resolve.
Comment 1 Kent Johnson CLA 2007-09-12 11:38:26 EDT
With the latest I build & the 3.3 build, I do get the problems mentioned on method1.

I do get the 2 errors on method2() :

"Method method2(T) has the same erasure method2(Object) as another method in type MyInterface<T>"

But we have no plans to change it - with generics, users are aware of erasures.
Comment 2 Simon Archer CLA 2007-09-12 13:00:29 EDT
The method1 name clash error was the most troubling, so it is good that it's gone.  I appreciate the argument for the erasure error message.  Thanks.
Comment 3 Jerome Lanneluc CLA 2007-09-18 05:46:30 EDT
Verified for 3.4M2