I have been programming in Java for several years and I do use generics but it seems my knowledge is incomplete because I don't fully understand the following:
What are the benefits of using List<?>
instead of List<T>
?
I do know that the question mark wildcard means any type (derived from Object
) but so is T
which can stand for any type. So is there a hidden benefit of using the former over the latter which I don't know about? or are they exactly the same?
How about List<? extends T>
versus List<E extends T>
?
Or MyType<?, ?>
versus MyType<E, T>
?
Edit: The thrust of my question here is different than another question asked here and none of the answers there answered my question. For example: I understand the difference between List<?>
and List<Long>
and when to use each one. My question is regarding List<?>
versus List<T>
where both ? and T can stand for any type.