Community
Participate
Working Groups
The following code is perfectly legal in java 1.5, javac compiles it, and it runs. It was not legal in java 1.4, and the Eclipse built-in compiler flags line 5 as an error, with the message "Incompatible conditional operand types int and String" public class Bug { public static void main(String[] args) { int foo = 0; String bar = "zero"; System.out.println( (foo != 0) ? foo : bar ); } }
Indeed, we did miss this scenario. Boxing is indicated in this case. Added AutoboxingTest#test109.
Fixed
is it possible to turn off that kind of error? Most of my code does not compiles due to this bug.
You could insert an ugly cast to workaround the bug. We will try to post you some patch. public class X { public static void main(String[] args) { int foo = 0; String bar = "zero"; System.out.println( (foo != 0) ? (Integer)foo : bar ); } }
Verified in 3.2 M1 with build I20050808-2000.
*** Bug 106499 has been marked as a duplicate of this bug. ***
Verified using M20050923-1430 for 3.1.1