JDK compiler error

Before anyone screams about the EOL'ed JDK, I would like to point out that my question is not about how to compile the following. There is a real question here, and it is not that JDK 1.5 is EOL'ed ...

Below in JDK 1.5, to 1.5.0_22 (the last I could find), a compiler error occurs on my system:

private Object[] boozinga() {
    boolean b = Math.abs(42) > 0;
    Object[] res = new Object[1];
    res[0] = b ? new int[1] : new String[1];
    return res;
}

Changing Math.abs (42)> 0 to true allows compilation.

Changing the triple "assignment" to if / else allows compilation.

Using JDK 1.6 allows compilation.

So, I was wondering: is there anything illegal in the above code for Java 1.5, and is this allowed in Java 1.6?

Crash for those under Java 1.5 too?

Failure says something like this:

(1.5.0_22). , Java Developer Connection (Http://java.sun.com/webapps/bugreport) . . .

, EOL'ed JDK - , , Java 1.5 .

+3
3

, . , JDK 1.6.0_21 -source 1.5 -target 1.5. JDK 1.6 JRE 1.5 ?

(JDK 1.5.0_12). :

public Object boozinga() {
    boolean b = true;
    Object res = b ? new int[1] : new String[1];
    return res;
}

, b ? new int[1] : new String[1] java.lang.Object & java.io.Serializable & java.lang.Cloneable.

+3

AutoBoxing-hell.

Integer [1] int [1].

: , , , , Eclipse.

JRE ( Eclipse JRE ), ecj35.jar . .

0

, b ? new int[1] : new String[1]. - ( 1.1.8 1.2, , , ), , .

 res[0] = b ? (Object)new int[1] : new String[1];

I didn’t look what it said about this language specification, but the compiler should never crash with an exception, it should give a real error message.

0
source

All Articles