• Post Reply Bookmark Topic Watch Topic
  • New Topic

Gnerics Doubt.  RSS feed

 
Sumukh Deshpande
Ranch Hand
Posts: 87
Firefox Browser IntelliJ IDE
  • Mark post as helpful
  • send pies
  • 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.

 
Campbell Ritchie
Marshal
Posts: 56562
172
  • Mark post as helpful
  • send pies
  • 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
Firefox Browser IntelliJ IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Campbell Ritchie.

Your explanation has cleared my doubts.
 
Campbell Ritchie
Marshal
Posts: 56562
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!