Thursday, March 31, 2011

Method has the same erasure bug in javac

Interesting bug in javac. Consider the two cases:
Case 1:
class Case1 {
    public String foo(Set<String> str) {
        return null;
    }

    public String foo(Set<Integer> str) {
        return null;
    }
}

Case 2:
class Case2 {
    public String foo(Set<String> str) {
        return null;
    }

    public Integer foo(Set<Integer> str) {
        return null;
    }
}

What do you think about them? Should Class1 compile? What about Class2?
In my opinion both of classes should not compile, since methods have the same erasure. In this is exactly what happens in Eclipse.
But, in IntelliJ the Class2 compiles just fine. And Maven also compiles the Class2 without problem.
So how does it happen?
It appears that Eclipse uses it own compiler, while Maven and IntelliJ use javac.
So where is the bug, in Eclipse or javac?
Here the bug that was opened in Eclipse community.
And here the bug in Sun (or should I say Oracle?)
So as you can see, both of them agree with me: the bug is in javac and not in Eclipse. Actually Sun marked it as fixed at 7(b55). Does it mean Java 7?

No comments: