Community
Participate
Working Groups
The following works without error in Eclipse Galileo (Version: 3.5.2, Build id: M20100211-1343) and results in error "Method same(List<Integer>) has the same erasure same(List<E>) as another method in type ErasureTest" in Eclipse Helios (Version: 3.6.0, Build id: I20100608-0911): public class ErasureTest { public Integer same(List<Integer> a) { return null; } public String same(List<String> b) { return null; } }
This code also compiles without error in javac 1.6.0_16. It's not clear that javac, or Eclipse 3.5.2, are correct, though. JLS 8.4.8 says: "It is a compile time error if a type declaration T has a member method m1 and there exists a method m2 declared in T [...] such that all of the following conditions hold: * m1 and m2 have the same name. * m2 is accessible from T. * The signature of m1 is not a subsignature (ยง8.4.2) of the signature of m2. * m1 [...] has the same erasure as m2 [...]." I've elided parts related to overriding, that don't matter here. Method erasure is defined in JLS 4.6: "The erasure of a method signature s is a signature consisting of the same name as s, and the erasures of all the formal parameter types given in s." So it hinges on whether the return type is part of the signature of a method. But in section 8.4.2, method signature is clearly defined to NOT include the return type: "Two methods have the same signature if they have the same name and argument types. Two method or constructor declarations M and N have the same argument types if all of the following conditions hold: * They have the same number of formal parameters (possibly zero) * They have the same number of type parameters (possibly zero) * Let <A1,...,An> be the formal type parameters of M and let <B1,...,Bn> be the formal type parameters of N. After renaming each occurrence of a Bi in N's type to Ai the bounds of corresponding type variables and the argument types of M and N are the same. The signature of a method m1 is a subsignature of the signature of a method m2 if either * m2 has the same signature as m1, or * the signature of m1 is the same as the erasure of the signature of m2. " Note also that in this case, neither method is a subsignature of the other: you'd have to erase _both_ signatures to get them to match. So in sum, it seems that Eclipse 3.6 is correct, and javac and Eclipse 3.5.2 are incorrect. JDT Core guys, assigning to you for confirmation.
Looks like a duplicate of bug 289247.
(In reply to comment #1) > This code also compiles without error in javac 1.6.0_16. On JDK7 (b91) it fails with (an essentially similar message to eclipse): ErasureTest.java:9: name clash: same(List<String>) and same(List<Integer>) have the same erasure public String same(List<String> b) { ^ 1 error > So in sum, it seems that Eclipse 3.6 is correct, and javac and Eclipse 3.5.2 > are incorrect. > > JDT Core guys, assigning to you for confirmation. Thanks for the (correct) analysis, Walter. (In reply to comment #2) > Looks like a duplicate of bug 289247. Yes, it is caused by bug 289247, however, I think it is better to classify it as a duplicate of bug# 317719. *** This bug has been marked as a duplicate of bug 317719 ***
Verified for 3.7M1
This problem can be avoided in some cases: public class ErasureTest { public <T_Result>T_Result same(List<T_Result> a) { return null; } } So you can use List<Integer> and List<String> as parameter "a". Maybe this will help some people...
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.8 M2