So I have gone through official java tutorial,https://docs.oracle.com/javase/tutorial/java/generics/index.html , also searched through stackoverflow, and it turns out that there is not much difference between using <E>
and <?>
, one as I can understand is normal generic form and the other one is wildcard. So far the only difference I came across is that when using <E>
or <E extetnds BlaBlaClass>
we can refer to the type as E
, while otherwise we don't know any information about the collection or array or the type at all.
My question is: is there any advantage of using <?>
(wildcard) over normal generics <E>
? and if so, what is the scenario of this situation? And why would someone use wildcards at all?
I have looked at Difference between generic type and wildcard type , Difference between ? (wildcard) and Type Parameter in Java , When to use generic methods and when to use wild-card? , Java Generics ? , E and T what is the difference? . So far it looks like <?>
is poorer version of <E>