Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In java what's the difference between ?, E, T [duplicate]

Tags:

java

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

like image 846
czetsuya Avatar asked Apr 03 '11 01:04

czetsuya


2 Answers

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

like image 116
jbrookover Avatar answered Sep 20 '22 22:09

jbrookover


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.

like image 24
Amir Afghani Avatar answered Sep 22 '22 22:09

Amir Afghani