Bug 316090

Summary: Overloaded methods with different type parameters cause compilation error.
Product: [Eclipse Project] JDT Reporter: Alessandro Nistico <alienisty>
Component: CoreAssignee: Srikanth Sankaran <srikanth_sankaran>
Status: CLOSED DUPLICATE QA Contact:
Severity: major    
Priority: P3 CC: amj87.iitr, srikanth_sankaran
Version: 3.6   
Target Milestone: 3.6 M2   
Hardware: PC   
OS: Windows XP   
Whiteboard:

Description Alessandro Nistico CLA 2010-06-08 01:44:12 EDT
Build Identifier: I20100603-1500

According to the JLS3.0 par 8.4.2 it should be possible to overload methods as in the following example:

public class BadOverloading {
  public int size(List<Integer> small) {
    return 0;
  }

  public long size(List<Long> large) {
    return 0L;
  }
}

In fact type parameters are part of the method signature and then, the methods in the example have different signature.
The above code causes a compilation error in eclipse, but it compiles fine with Sun's (Oracle) jdk1.6.0_20.

I've tested the same code with eclipse 3.5.2 M20100211-1343 and it compiles as expected.


Reproducible: Always

Steps to Reproduce:
Use the example in the details.
Comment 1 Srikanth Sankaran CLA 2010-06-08 02:29:34 EDT
This is a defect in the Sun/Oracle compiler.
See http://bugs.sun.com/view_bug.do?bug_id=6182950
fixed and released only in the JDK 7 stream.

Accordingly if I compile the snippet attached
to this bug using javac 7 I get:

BadOverloading.java:7: name clash: size(List<Long>) and size(List<Integer>) have
 the same erasure
  public long size(List<Long> large) {
              ^
1 error

(In reply to comment #0)

> In fact type parameters are part of the method signature and then, the methods
> in the example have different signature.

List<Long> and List<Integer> both decay to just List after type erasure.
So there is no difference in the method signature and both methods have
the same erasure and hence constitute an error according to JLS 8.4.8.3

*** This bug has been marked as a duplicate of bug 289247 ***
Comment 2 Ayushman Jain CLA 2010-06-09 02:55:14 EDT
Verified for 3.6RC4 using build I20100603-1500.