• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Devaka Cooray
  • Ron McLeod
  • paul wheaton
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Frits Walraven
  • Scott Selikoff

again doubt in generic

 
Ranch Hand
Posts: 383
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 694
Mac OS X Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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,
 
Ranch Hand
Posts: 1274
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Chandra.
We can use any of them. Am I right?
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
The only thing that kept the leeches off of me was this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic