且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

为什么这个程序可以用 Java 7 而不是 Java 8 编译?

更新时间:2022-01-02 01:35:55

旧行为不是错误,新行为也不是错误.条件表达式类型的规则变得更加复杂,这在很多情况下都有帮助,而对您的情况并没有真正的伤害.

Neither was the old behavior a bug, nor is the new behavior a bug. The rules for the type of the conditional expression just got more complex, which helps in many cases and doesn't really hurt in yours.

编译器不允许,因为Integer.classFloat.class 的类型不可比.没有类型 T 会使 Class 成为 ClassClass.

The compiler does not allow it because the types of Integer.class and Float.class are incomparable. There is no type T which would make Class<T> a supertype of both Class<Integer> and Class<Float>.