• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Gnerics Doubt.

 
Ranch Hand
Posts: 87
IntelliJ IDE Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am reading a tutorial on Generics. I have come across a doubt.
Here is the tutorial

For convenience I am pasting the code.
In tutorial type erasure phenomena in Generics is explained.
So the code below is before Type Erasure:




After Type Erasure it becomes:



Now my doubts are:

1. What does this mean in <br />

2. Also in tutorial it is said that Type Erasure it is said that:

When the compiler finds the definition of a generic type or method, it removes all occurrences of the type parameters and replaces them by their leftmost bound, or type Object if no bound had been specified.


What does it mean here by leftmost bound?

Please help me to clear the doubt.
Thanks in advance.

 
Marshal
Posts: 79179
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There are other tutorials, eg the Java™ Tutorials, which has two sections about generics in. You might find that easier to understand. But Angelika Langer is usually very good.

There is a problem that in some instances < appears as ><; I have tried to correct that in your post.

What <T extends Comparable<T>> means is that you have to have a particular type "T", and that type has to implement the Comparable interface. And that Comparable interface has to compare to the same type "T". Actually, I think the usual style is <T extends Comparable<? super T>> which means that the Comparable methods must take a "T" or any of its superclasses as its type.
I think the bit about "leftmost bound" means that the types are changed to the type which is highest (ie nearest to java.lang.Object) in its inheritance tree.

Note you write extends in generics, not implements.
 
Sumukh Deshpande
Ranch Hand
Posts: 87
IntelliJ IDE Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Campbell Ritchie.

Your explanation has cleared my doubts.
 
Campbell Ritchie
Marshal
Posts: 79179
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're welcome
reply
    Bookmark Topic Watch Topic
  • New Topic