Saturday, November 18, 2006

Bugs in Eclipse Java compiler (part I)

Version: 3.2.1; Build id: M20060921-0945

Try this one:

public abstract class AbstractClass<T> {
AbstractClass(T obj) {
System.out.println(obj.toString());
}

AbstractClass(String string) {
System.out.println(string);
}
}

and this:

public class Implementation extends AbstractClass<String> {
public Implementation(String obj) {
super(obj);
}
}

Eclipse' compiler will compile two above classes without any warning but when you try to compile this with Sun's original Java compiler (javac 1.5.0_05 in my case - this is the command: javac *.java) you will get such error message:

Implementation.java:3: reference to AbstractClass is ambiguous,
both method AbstractClass(T) in generics.AbstractClass and method
AbstractClass(java.lang.String) in generics.AbstractClass
match
super(obj);
^
1 error

I don't have much time for reporting this bug to Eclipse bugzilla, so if you have some time please do so (if it is not already reported).

BTW. I had to solve this problem because I wanted implementing classes to have both constructors. The solution is to change one of the constructors in AbstractClass that it looks like this one:

AbstractClass(String string, boolean fakeFlag) {
System.out.println(string);
}

This way you get rid of ambiguity.

PS. (2008-11-24) It is already fixed - it was indeed an Eclipse compiler bug but don't ask about any dates and versions - I don't have them.

No comments: