What is the difference between ‘E’, ‘T’, and ‘?’ for Java generics?

Well there’s no difference between the first two – they’re just using different names for the type parameter (E or T).

The third isn’t a valid declaration – ? is used as a wildcard which is used when providing a type argument, e.g. List<?> foo = ... means that foo refers to a list of some type, but we don’t know what.

All of this is generics, which is a pretty huge topic. You may wish to learn about it through the following resources, although there are more available of course:

  • Java Tutorial on Generics
  • Language guide to generics
  • Generics in the Java programming language
  • Angelika Langer’s Java Generics FAQ (massive and comprehensive; more for reference though)

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)