Community
Participate
Working Groups
Eclipse 3.2M3 public class Test { public static void main(String[] args) { Object obj = true ? true : 17.3; } } Eclipse says: Incompatible conditional operand types Boolean and double JLS says: Otherwise, the second and third operands are of types S1 and S2 respectively. Let T1 be the type that results from applying boxing conversion to S1, and let T2 be the type that results from applying boxing conversion to S2. The type of the conditional expression is the result of applying capture conversion to lub(T1, T2). As I understand it: S1 = boolean, S2 = double T1 = Boolean, T2 = Double lub(T1, T2) = something assignment compatible with Object capture applied to lub(T1, T2) = lub(T1, T2) Therefore, the expression is valid and should yield Boolean.TRUE. Eclipse seems to have applied boxing conversion to the second argument, but not to the third argument, and thus failed. Oddly enough: Object obj = true ? true : Double.valueOf(17.3); Eclipse gives the same error. It converts true to type Boolean by boxing conversion, AND Double.valueOf(17.3) to double by unboxing conversion, and THEN gets stuck.
Good find. Indeed the compiler logic is wrong. It must promote both operands in this situation (bogus 'else' in between to IFs). Added AutoboxingTest#test117
should backport to 3.1.x
Fixed in 3.2 and 3.1.x streams.
Verified for 3.2 M5 using build I20060215-0010