Bug 275653 - [1.5][compiler] Incorrect generics behaviour
Summary: [1.5][compiler] Incorrect generics behaviour
Status: VERIFIED NOT_ECLIPSE
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.4   Edit
Hardware: PC All
: P3 normal (vote)
Target Milestone: 3.5 RC1   Edit
Assignee: Kent Johnson CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-05-11 09:36 EDT by Evans CLA
Modified: 2009-05-14 12:24 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 Evans CLA 2009-05-11 09:36:54 EDT
class Addables<T extends Integer> {
	void addThem(T a, T b) {
		System.out.print(a + b);

	}

	public static void main(String[] args) {
		new Addables<Integer>().addThem(40, 2);
	}
}

Compiles and runs giving 42 as output on eclipse using both JDKs 1.5 and 1.6.


Doesn't compile on Sun's JDKs.
Comment 1 Olivier Thomann CLA 2009-05-11 09:42:22 EDT
This compiles fine on JDK7b57.
d:\tests_sources>javac X.java

d:\tests_sources>java -version
java version "1.7.0-ea"
Java(TM) SE Runtime Environment (build 1.7.0-ea-b57)
Java HotSpot(TM) Client VM (build 16.0-b02, mixed mode)

It doesn't compile on JDK6 build 1.6.0_14-ea-b05.
d:\tests_sources>javac X.java
X.java:8: cannot find symbol
symbol  : method valueOf(int)
location: bound of type variable T
                new X<Integer>().addThem(40, 2);
                                         ^
Fatal Error: Unable to find method valueOf
Comment 2 Evans CLA 2009-05-11 09:50:40 EDT
It compiles and runs on eclipse using JRE for 1.6.0_06 though.

I don't have jdk7 yet so I didn't test there. Does that mean it's a Sun bug fixed in JDK 7?
Comment 3 Philipe Mulet CLA 2009-05-11 10:46:31 EDT
Generic inference is supposed to use boxing conversion when applicable, so yes it should work.
Comment 4 Kent Johnson CLA 2009-05-12 16:00:06 EDT
Closing as NOT_ECLIPSE since this is fixed in javac 7 & may eventually get backported to a java 6 build
Comment 5 Olivier Thomann CLA 2009-05-14 12:24:51 EDT
Verified for 3.5RC1 using I20090511-2000.