Java 6.0 widening conversion bug?
807588Jul 17 2009 — edited Jul 17 2009a)
Byte test = (byte)10; // works
Short test = (byte)10; // works
Integer test = (byte)10; // works
Long test = (byte)10; // doesn't work
Float test = (byte)10; // doesn't work
Double test = (byte)10; // doesn't work
Summary: seems like it does a promotion to a max of Integer
b)
final byte x = 10; Byte y = x; // works
final byte x = 10; Short y = x; // works
final byte x = 10; Integer y = x; // works
final byte x = 10; Long y = x; // doesn't work
final byte x = 10; Float y = x; // doesn't work
final byte x = 10; Double y = x; // doesn't work
Summary : seems like it does a promotion to a max of Integer and only if the variable is final.
Question: Why does it need a variable to be final to be promoted? Final is used for constant expression to be used for implicit narrowing conversion.
c)
byte x = 10; Byte y = x; // works
byte x = 10; Short y = x; // doesn't work
byte x = 10; Integer y = x; // doesn't work
byte x = 10; Float y = x; // doesn't work
byte x = 10; Double y = x; // doesn't work
Without finals .. it fails at short.
Strange ..