15

Possible Duplicate:
Java Generics

Hi,

Can anyone please explain the difference of the three and each proper usage?

Thanks, been googling but I'm still confused on how to use each.

czetsuya

Community
  • 1
  • 1
czetsuya
  • 4,773
  • 13
  • 53
  • 99

2 Answers2

14

I'm assuming you're talking about Generics. The 'E' and 'T' are placeholders and can be used interchangeably in class definitions. By convention 'E' is an Element and 'T' is a Type. The question mark is a placeholder for an unknown type. You often see things like this:

List<? extends MyObject> x;

This implies that 'x' is a list of objects that are subclasses of MyObject, but we don't know what they are exactly.

See: http://docs.oracle.com/javase/tutorial/java/generics/genTypes.html

user4975679
  • 1,461
  • 16
  • 21
jbrookover
  • 5,100
  • 1
  • 23
  • 23
5

E, T, K, V, or any other generic type variables are just placeholders - they don't have any intrinsic association. You can even use lowercase letters for generic type variables, but conventionally you use a single capital letter. Read the generics tutorial from Sun.

Amir Afghani
  • 37,814
  • 16
  • 84
  • 124