Community
Participate
Working Groups
Build Identifier: 20100617-1415 I have the following test class that uses generics to overload a method. It works when compiled with javac and fails to compile in Eclipse Helios. The error is : Method getFirst(ArrayList<String>) has the same erasure getFirst(ArrayList<E>) as another method in type Test My java version is 1.6.0_21. All the articles I read indicate that Eclipse is right and this code should not work. However when compiled with javac and run, the right method is selected. How is this possible? import java.util.ArrayList; public class Test { public static void main (String [] args) { Test t = new Test(); ArrayList<String> ss = new ArrayList<String>(); ss.add("hello"); ss.add("world"); ArrayList<Integer> is = new ArrayList<Integer>(); is.add(1); is.add(2); System.out.println(t.getFirst(ss)); System.out.println(t.getFirst(is)); } public String getFirst (ArrayList<String> ss) { return ss.get(0); } public Integer getFirst (ArrayList<Integer> ss) { return ss.get(0); } } Reproducible: Always Steps to Reproduce: 1. Paste the test code above into an Eclipse buffer. 2. 3.
(In reply to comment #0) > Build Identifier: 20100617-1415 > All the articles I read indicate that Eclipse is right and this code should not > work. However when compiled with javac and run, the right method is selected. > > How is this possible? Eclipse behavior is the right one and the javac bug has since been fixed in the JDK7 stream. I have verified that your sample code fails to compile with JDK 7b100 compiler. *** This bug has been marked as a duplicate of bug 317719 ***
Verified for 3.7M2.
junit has been added as a part of the fix for bug 317719
Verified for 3.7.1 RC2 using build M20110824-0800
Verified for 3.8M2 using build I20110912-0800