How does the Java compiler do type erasure for lower bounded wildcards?

When compiling source code with generic types, the Java compiler automatically erases the type, replacing general declarations with the corresponding source types.

According to Oracle docs, this erase replaces the top related wildcard character <? extends T> <? extends T> on T. This is consistent with dynamic polymorphism.

But how is this erasure done for the lower bounded wildcard <? super T> <? super T> , seeing that each class has a common superclass (Object), using which will defeat the whole goal?

+6
source share
1 answer

For a supertype, it is erased to the type of object. <?super T> used only to check compile time

+6
source

Source: https://habr.com/ru/post/974289/


All Articles