java - JDK 编译错误

标签 java exception compiler-construction

在有人尖叫 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/

相关文章:

iphone - 从后台恢复应用程序时 RestKit 崩溃

Java编译器: Is it possible to feed in variables on run

c - "Too few arguments"错误试图运行我编译的程序

时间:2019-03-08 标签:c++typeidoperator

java - 如何从android中的Activity启动一个java线程

java - 从回调内部重新抛出 Throwable

java - jpa (Hibernate) 中具有重复行的结果集

c# - 处理未处理的异常问题

java - 康威的生命游戏在数邻居时越界 - java

java - 为什么在 Java 中使用正则表达式会在运行时抛出 "Unclosed character class"异常?