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

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: 79977
396
  • 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: 79977
396
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're welcome
 
Opportunity is missed by most people because it is dressed in overalls and looks like work - Edison. Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic