Community
Participate
Working Groups
Reproduced with Eclipse 3.2M6 on Windows XP, but also reproduced by a colleague (i.e. uncomfirmed) on Eclipse 3.1.2 Running on Sun JDK 1.5.0 This is not a problem in the 5.0 compiler compliance level. Set the compliance level to 1.3 or 1.4 (with default compliance settings), and put the following classes in a project: public interface I { } public class A implements I { } public class B implements I { } public class Test { public static void main(String[] args) { I i = true ? new A() : new B(); } } The ternary operator line shows an error and says "Incompatible conditional operand types A and B"
Actually, this may (oddly) be the "correct" behavior. The Sun 1.5 JDK's javac shows the same error in 1.4 compliance mode, but not in default compliance mode (1.5). This bug may be invalid.
Yes, this behavior is intended. With Java5, the compiler is now inferring most specific common supertype, in 1.4 you had to tell him explicitly (i.e. inserted a cast to (I) on one operand). Working as intended.