aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes why is Comparable interface extended? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "why is Comparable interface extended?" Watch "why is Comparable interface extended?" New topic
Author

why is Comparable interface extended?

Roshan Rai
Greenhorn

Joined: Aug 16, 2012
Posts: 15
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..
Karthikeyan Kandasamy
Greenhorn

Joined: Apr 17, 2011
Posts: 14
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
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

for JRE i believe no difference between marker and other interface.....
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4465
    
    8

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: why is Comparable interface extended?