Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 322371 - Java generics code compiles with javac, fails with Eclipse Helios
Summary: Java generics code compiles with javac, fails with Eclipse Helios
Status: VERIFIED DUPLICATE of bug 317719
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.7   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: 3.7.1   Edit
Assignee: Srikanth Sankaran CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-08-11 10:44 EDT by aditya.siram CLA
Modified: 2011-09-14 02:23 EDT (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description aditya.siram CLA 2010-08-11 10:44:37 EDT
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.
Comment 1 Srikanth Sankaran CLA 2010-08-11 13:33:28 EDT
(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 ***
Comment 2 Olivier Thomann CLA 2010-09-14 10:03:19 EDT
Verified for 3.7M2.
Comment 3 Srikanth Sankaran CLA 2011-08-09 10:12:58 EDT
junit has been added as a part of the fix for bug 317719
Comment 4 Satyam Kandula CLA 2011-08-25 09:05:05 EDT
Verified for 3.7.1 RC2 using build M20110824-0800
Comment 5 Satyam Kandula CLA 2011-09-14 02:23:47 EDT
Verified for 3.8M2 using build I20110912-0800