下面的代码在一些 IDE 而不是在一些 IDE "Java is Unsound" 中编译
Below Code is compiling in some IDE and not in some IDE "Java is Unsound"
Java 不健全 https://hackernoon.com/java-is-unsound-28c84cb2b3f#.8tf5qumlb
本文 java 讨论了类型安全,它在某些 java 版本中编译,在某些 java 版本中不编译。
class Unsound {
static class Constrain<A,B extends A>{}
static class Bind<A> {
<B extends A>
A upcast(Constrain<A,B> constrain , B b){
return b;
}
}
static <T,U> U coerce(T t){
Constrain<U,? super T> constrain = null;
Bind <U> bind = new Bind<U>();
return bind.upcast(constrain,t);
}
public static void main(String ...s){
String zero = Unsound.<Integer,String>coerce(0);
}
}
https://raw.githubusercontent.com/namin/unsound/master/doc/unsound-oopsla16.pdf
因此,如果他们说这归结为空指针错误。但与大多数空指针错误不同
所以只是无法理解它在不同IDE
上的编译或非编译
一个开放的错误也与之相关https://bugs.openjdk.java.net/browse/JDK-8054941
并且 eclipse 也 https://bugs.eclipse.org/bugs/show_bug.cgi?id=510900
您问题的答案在您引用的文章中。
If your compiler doesn’t type-check our example, I have news for you. No, your compiler isn’t catching the bug. In fact, your compiler itself has a bug. Your compiler is broken. The Java specification says this example should type check and compile.
现在只需将其与不同的 IDE 可能使用不同的编译器这一事实相结合(Eclipse 使用它自己的编译器,IntelliJ 默认使用 javac,但它是可配置的,等等),你就得到了你的怀疑。 :)
Java 不健全 https://hackernoon.com/java-is-unsound-28c84cb2b3f#.8tf5qumlb
本文 java 讨论了类型安全,它在某些 java 版本中编译,在某些 java 版本中不编译。
class Unsound {
static class Constrain<A,B extends A>{}
static class Bind<A> {
<B extends A>
A upcast(Constrain<A,B> constrain , B b){
return b;
}
}
static <T,U> U coerce(T t){
Constrain<U,? super T> constrain = null;
Bind <U> bind = new Bind<U>();
return bind.upcast(constrain,t);
}
public static void main(String ...s){
String zero = Unsound.<Integer,String>coerce(0);
}
}
https://raw.githubusercontent.com/namin/unsound/master/doc/unsound-oopsla16.pdf
因此,如果他们说这归结为空指针错误。但与大多数空指针错误不同
所以只是无法理解它在不同IDE
上的编译或非编译一个开放的错误也与之相关https://bugs.openjdk.java.net/browse/JDK-8054941
并且 eclipse 也 https://bugs.eclipse.org/bugs/show_bug.cgi?id=510900
您问题的答案在您引用的文章中。
If your compiler doesn’t type-check our example, I have news for you. No, your compiler isn’t catching the bug. In fact, your compiler itself has a bug. Your compiler is broken. The Java specification says this example should type check and compile.
现在只需将其与不同的 IDE 可能使用不同的编译器这一事实相结合(Eclipse 使用它自己的编译器,IntelliJ 默认使用 javac,但它是可配置的,等等),你就得到了你的怀疑。 :)