| Author |
again doubt in generic
|
dolly shah
Ranch Hand
Joined: Jun 18, 2007
Posts: 383
|
|
What is the main difference between <E> & <T> type. In book its written that <E> is used for Collection. <T> is used for things that are not collection. But I am not getting it. Where we can you <E> & where we can use <T>? Please anybody help me.
|
SCJP-1.5<br />SCWCD-1.4
|
 |
Kaydell Leavitt
Ranch Hand
Joined: Nov 18, 2006
Posts: 682
|
|
It doesn't matter which letter that you use to specify a generic type. It's just that once you use a letter to specify a type, using the same letter again, in the same context means that you're referring to the same type. E & T are like variables only instead of representing primitives or objects, they represent types. Kaydell
|
 |
Chandra Bhatt
Ranch Hand
Joined: Feb 28, 2007
Posts: 1707
|
|
Hi, It is often seen as convention while naming parameterized type: Letter E generally used with parameterized interfaces like: Letter T is also used interchangeably. Thanks,
|
cmbhatt
|
 |
Burkhard Hassel
Ranch Hand
Joined: Aug 25, 2006
Posts: 1274
|
|
Hi ranchers, Gilad Bracha wrotes in his generics tutorial that the naming convention is either <T> for type or (esp. in collections) <E> for element. The tutorial (PDF) can be downloaded from Sun at: http://java.sun.com/j2se/1.5/pdf/generics-tutorial.pdf Yours, Bu.
|
all events occur in real time
|
 |
dolly shah
Ranch Hand
Joined: Jun 18, 2007
Posts: 383
|
|
In book its written that <E> is used for Collection. <T> is used for things that are not collection. Wy they have written above sentence? If there is no difference, Why they have introduced (<E> & <T> ?
|
 |
dolly shah
Ranch Hand
Joined: Jun 18, 2007
Posts: 383
|
|
Thanks Chandra. We can use any of them. Am I right?
|
 |
Jesper de Jong
Java Cowboy
Bartender
Joined: Aug 16, 2005
Posts: 12950
|
|
Yes, you can also use something else than "E" or "T". It doesn't even have to be a single letter, you can use any name.
|
Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
|
 |
Kantutan Tayo
Greenhorn
Joined: Oct 07, 2005
Posts: 22
|
|
It's just by code convention / suggestion. E stands for Element (an element within a collection) T stands for Type (a generic type) It could have been a complete word instead of just a letter e.g. interface Comaparable<Elephant> { int compareTo(Elephant e); } But that's gay.
|
SCJP
|
 |
 |
|
|
subject: again doubt in generic
|
|
|