Bug 316090 - Overloaded methods with different type parameters cause compilation error.
Summary: Overloaded methods with different type parameters cause compilation error.
Status: CLOSED DUPLICATE of bug 289247
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.6   Edit
Hardware: PC Windows XP
: P3 major (vote)
Target Milestone: 3.6 M2   Edit
Assignee: Srikanth Sankaran CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-06-08 01:44 EDT by Alessandro Nistico CLA
Modified: 2010-06-09 02:55 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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.