0

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.

Community
  • 1
  • 1
Thomas Nguyen
  • 464
  • 1
  • 5
  • 16
  • Really go see the other question and read the comments. But I tink that you should use names if you need to ensure type, and wildcard if you dont. – Marcos Vasconcelos Jun 22 '15 at 21:02
  • @Marcos, I appreciate your response but it is not helpful to me. I asked a very specific question, `List>` versus `List` and you answered with a broad principle, which I already indicated I understood that principle with the `List>` versus `List` example. I have read the answers to other question and they all give examples of how to apply the principle you mentioned but never directly answer my original question. – Thomas Nguyen Jun 22 '15 at 21:10
  • I just said that you can ensure types using name, its not really your answer. – Marcos Vasconcelos Jun 22 '15 at 21:23

0 Answers0