How does the Java compiler perform type erasure fo

2020-07-09 03:26发布

问题:

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?

回答1:

For super type,it erases to Object type.<?super T> is only used for compile time verification