Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • Devaka Cooray
Saloon Keepers:
  • Ganesh Patekar
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • salvin francis
Bartenders:
  • Ron McLeod
  • Frits Walraven
  • Pete Letkeman

Gnerics Doubt.  RSS feed

 
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.

 
Marshal
Posts: 60914
190
  • 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: 60914
190
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!