• 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
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

why is Comparable interface extended?

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello..

i got doubt...




(Cross is an interface)..

Comparable being an interface why is it extended instead of implementing..??
and what is the actual use of Comparable interface...why it is used..??

thanks in advance..
 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In this case, extends applies to both subclasses and interfaces. Other keyword which can be used in generic type definition is "super". But I am not sure why "implements" is not used here.

Source: K&B SCJP book
Page : 618
Chapter: Generics and Collections
 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
for JRE i believe no difference between marker and other interface.....
 
Bartender
Posts: 4568
9
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Comparable is used to define a natural order of a class, so that sort routines (such as Collections.sort()) are able to sort them. To be able to sort objects, you have to have a way of defining what order they should come in - we can do this by implementing Comparable.

The generic constraint you see there is really a bit different to implementation. The word extends is used regardless of whether you're referring to a class or an interface, because in this context it's not really important. And also, E could refer to an interface, and interfaces extend other interfaces.
 
If you settle for what they are giving you, you deserve what you get. Fight for this tiny ad!
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic