简体   繁体   English

Java编译器如何为较低边界的通配符执行类型擦除?

[英]How does the Java compiler perform type erasure for lower bounded wildcards?

While compiling source code with generic types, the Java compiler automatically performs type erasure, replacing the generic declarations with suitable raw types. 在使用泛型类型编译源代码时,Java编译器会自动执行类型擦除,用适当的原始类型替换泛型声明。

As per the Oracle docs, this erasure replaces the upper bonded wildcard <? extends T> 根据Oracle文档,这个擦除取代了上面的绑定通配符<? extends T> <? extends T> with T. This fits well with dynamic polymorphism. 使用T <? extends T>这非常适合动态多态。

But how is this erasure performed for lower bounded wildcard <? super T> 但是对于有界较低的通配符<? super T>如何执行此擦除<? super T> <? super T> seeing that every class has a common super class (Object), using which will defeat the whole purpose? <? super T>看到每个类都有一个共同的超类(Object),使用它会破坏整个目的吗?

For super type,it erases to Object type. 对于超类型,它将擦除为对象类型。 <?super T> is only used for compile time verification <?super T>仅用于编译时验证

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM