This week's book giveaway is in the Jython/Python forum.
We're giving away four copies of Murach's Python Programming and have Michael Urban and Joel Murach on-line!
See this thread for details.
Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

again doubt in generic  RSS feed

 
dolly shah
Ranch Hand
Posts: 383
  • 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: 690
Eclipse IDE Firefox Browser Mac OS X
  • 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
  • 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
  • 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
  • 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
  • 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
Sheriff
Posts: 15861
81
Android IntelliJ IDE Java Scala Spring
  • 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
  • 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.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!