FULL PRODUCT VERSION :
java version "1.7.0_01"
Java(TM) SE Runtime Environment (build 1.7.0_01-b08)
Java HotSpot(TM) Client VM (build 21.1-b02, mixed mode, sharing)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.1.7601]
A DESCRIPTION OF THE PROBLEM :
When compiling the given test case with javac we get a compile time error for Integer i2 = (byte)3. Explicitly using Integer.valueOf( (byte)3); on the other hand works.
The eclipse compiler compiles both variants fine and I don't see anything in the JLS wrt autoboxing that explains the behavior of javac. Since the compiler should create a valueOf call in the background anyhow and doing that explicitly works fine.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Compile the test case with javac.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
No compile time error.
ACTUAL -
Test.java:4: error: incompatible types
Integer i2 = (byte)3;
^
required: Integer
found: byte
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
public class Test {
public static void main(String[] args) {
Integer i1 = Integer.valueOf((byte)3); // works fine with all compilers
Integer i2 = (byte)3; // works fine with eclipse compiler, not javac
}
}
---------- END SOURCE ----------