java generics bounded wildcards `? super ? extends T`

101 views Asked by At

I stumble upon this problem million of times and I can't wrap my head around it.

Let's assume I have a stream seq of type Stream<? extends T> and I want to execute a forEach on its elements.

The type of the consumer now becomes a Consumer<? super ? extends T>, now how does java treat a generic type ? super ? extends T ?

Is it the equivalent of ? super T, because the generic type ? extends T is considered as a T in this example.

Someone please provide the exact procedure of how the java compiler treats the following situations.

0

There are 0 answers