Community
Participate
Working Groups
I do not know what JLS has to say about this, but the following code compiles by javac 1.5 but not by cheetah. Error mesage is "Incompatible conditional operand types C1 and C2" -------------------------- package test.cheetah; import java.util.ArrayList; public class Test { private static class C1 extends ArrayList { } private static class C2 extends ArrayList { } ArrayList method(boolean param) { return param? new C1(): new C2(); } } -------------------------- Note that javac 1.4.2 does not compile this code (error message "incompatible types for ?: neither is a subtype of the other"). eclipse 200406111814, cheetah from CVS as of late afternoon June 16 EDT ;-)
Interesting...
Out of curiosity, why eclipse/old javac complain about this? Target type of this expression (ArrayList) is known and both C1 and C2 can be casted to that type, so what's wrong whith that?
Under JLS2, one of the operand has to be assignable to the other (i.e. C1 assignable to C2 or reciprocal). It looks like JLS3 allow inference of most common supertype (which makes sense).
New behavior is implemented from -source 1.5 on.
Regression test added: Compliance_1_5#test080.
Fixed