我发现 java8 有一个奇怪的问题:
在类方法中,我有以下代码:
int id;
...
new Key<Integer>(id)
要删除作为键的“类型参数的冗余规范”,我写:
new Key<>(id)
然后我得到一个
java.lang.VerifyError: Bad type on operand stack
在执行时...!!!!原因:编译器忽略了将 int 替换为 Integer...
希望这能帮助像我这样的人,因为他们的程序刚刚从 java7 传递到 java8 而对这种运行时异常感到非常失望....
版本:Luna Release (4.4.0) 构建 ID:20140612-0600
Java 版本“1.8.0_25” Java(TM) SE 运行时环境(build 1.8.0_25-b17) Java HotSpot(TM) 64 位服务器 VM(构建 25.25-b02,混合模式)
已添加
这是一个完整的简单示例:
package bug;
public class Bug {
public static void main(String[] args) {
Bug.class.getConstructors();
System.out.println("test ok");
}
public Bug() {
BugCondition("", new Key<Integer>(1));
//BugCondition("", new Key<>(1));
}
public static final <C extends Object> void BugCondition(C test, Key<?> key) {
}
public class Key<K> {
public Key(K value) {
}
}
}
问题似乎来自泛型(用字符串替换 C):
public static final <C extends Object> void BugCondition(C test, Key<?> key) {
}
最佳答案
您的示例使用 Eclipse Mars 编译得非常好.我正在使用以下构建:
Version: Mars Release Candidate 2 (4.5.0RC2)
Build id: 20150528-0540
我怀疑此问题已同时得到解决(就像许多其他 Eclipse/Java8 编译问题一样)
关于java-8 - Java8 eclipse 编译器错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26809960/