Community
Participate
Working Groups
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.
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
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?
Generic inference is supposed to use boxing conversion when applicable, so yes it should work.
Closing as NOT_ECLIPSE since this is fixed in javac 7 & may eventually get backported to a java 6 build
Verified for 3.5RC1 using I20090511-2000.