Java编译器如何对下界有界的通配符执行类型擦除? [英] How does the Java compiler perform type erasure for lower bounded wildcards?
问题描述
使用泛型类型编译源代码时,Java编译器自动执行类型擦除,用合适的原始类型替换泛型声明。
根据Oracle文档,擦除会替换上面的保税通配符<使用T扩展T>
。这符合动态多态性。
但是,如何擦除下限通配符< ;?看看每个类都有一个共同的超类(Object),使用它会失败的全部目的?
<?super T>
仅用于编译时验证 While compiling source code with generic types, the Java compiler automatically performs type erasure, replacing the generic declarations with suitable raw types.
As per the Oracle docs, this erasure replaces the upper bonded wildcard <? extends T>
with T. This fits well with dynamic polymorphism.
But how is this erasure performed for lower bounded wildcard <? super T>
seeing that every class has a common super class (Object), using which will defeat the whole purpose?
For super type,it erases to Object type.<?super T>
is only used for compile time verification
这篇关于Java编译器如何对下界有界的通配符执行类型擦除?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!