Community
Participate
Working Groups
Test case: public class X { public static void main(String[] args) { boolean b = true; Character _Character = new Character(' '); char c = ' '; Integer _Integer = new Integer(2); if ((b ? _Character : _Integer) == c) { System.out.println("SUCCESS"); } else { System.out.println("FAILURE"); } } } javac can successfully compile it. It converts the _Character to its charValue() and the _Integer to its intValue(). We fail with: ---------- 1. ERROR in C:\tests_sources\X.java (at line 7) if ((b ? _Character : _Integer) == c) { ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Incompatible operand types Object and char ---------- 1 problem (1 error) Note that it doesn't work anymore if you extract the conditional expression in a local variable of type Object.
As soon as both operands are numeric using unboxing, conditional operator is unboxing both operands. So bool ? Integer : Character ==> bool ? int : char. We were incorrectly letting it use the reference type scenario instead. Added AutoboxingTest#test095-096 Fixed
Verified in I20050214