在有人尖叫 EOL'ed JDK 之前,我想指出我的问题不是关于如何编译以下内容。这里有一个真正的问题,这与 JDK 1.5 的 EOL 无关......
在 JDK 1.5 下,直到 1.5.0_22(我能找到的最后一个)在我的系统上产生编译器错误:
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;
}
将 Math.abs(42) > 0 更改为 true 允许编译。
将三元“赋值”更改为 if/else 允许编译。
使用 JDK 1.6 允许编译。
所以我想知道:上面的代码在 Java 1.5 下是不是有什么不合法而在 Java 1.6 下是允许的?
对于那些使用 Java 1.5 的人来说,它也会崩溃吗?
崩溃是这样的:
An exception has occured in the compiler (1.5.0_22). Please file a bug at the Java Developer Connection (http://java.sun.com/webapps/bugreport) after checking the Bug Parade for duplicates. Include your program and the following diagnostic in your report. Thank you.
我认为为 EOL 的 JDK 填写错误报告是徒劳的,但我仍然想知道以上是否是有效的 Java 1.5 代码。
最佳答案
我认为这是合法的。证据是 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
。
关于java - JDK 编译错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6205008/