Bug 81923 - In certain cases generics seens to be applied before autoboxing.
Summary: In certain cases generics seens to be applied before autoboxing.
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.1   Edit
Hardware: PC Windows 2000
: P3 normal (vote)
Target Milestone: 3.1 M5   Edit
Assignee: Kent Johnson CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-12-27 05:20 EST by Todor Boev CLA
Modified: 2005-02-16 05:47 EST (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Todor Boev CLA 2004-12-27 05:20:16 EST
The following code compiles and executes fine with JDK 1.5.0_01 but does not 
compile with Eclipse 3.1M4:

public class Box<T> {
  private T t;

  public <A extends T> Box(A t) {
    this.t = t;
  }
  
  public String toString() {
    return "[" + t + "]";
  }
  
  public static void main(String[] args) { 
    //primitive type - error in eclipse
    System.out.println(new Box<Integer>(10));
    
    //primitive type - workarround for eclipse.
    System.out.println(new Box<Integer>(new Integer(10)));
    
    //reference type - fine everyware
    System.out.println(new Box<String>("alabala"));
  }
}

The compiler issues the following message:
"Bound mismatch: The generic constructor Box(A) of type Box<T> is not applicable 
for the arguments (int) since the type int is not a valid substitute for the 
bounded parameter <A extends T>"

Seems in this particular case the compiler applies generics on the primitive 
type (int) before it applies autoboxing to conver it to a valid reference type 
(Integer).
Comment 1 Kent Johnson CLA 2005-01-10 18:30:48 EST
Added AutoBoxing test078.
Comment 2 David Audel CLA 2005-02-16 05:47:53 EST
Verified in I20050215-2300