File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

again doubt in generic

 
dolly shah
Ranch Hand
Posts: 383
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Kaydell Leavitt
Ranch Hand
Posts: 689
Eclipse IDE Firefox Browser Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1710
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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,
 
Burkhard Hassel
Ranch Hand
Posts: 1274
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
dolly shah
Ranch Hand
Posts: 383
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 383
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Chandra.
We can use any of them. Am I right?
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Pie
Posts: 15150
31
Android IntelliJ IDE Java Scala Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Kantutan Tayo
Greenhorn
Posts: 22
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic