Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

why is Comparable interface extended?

 
Roshan Rai
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • 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..
 
Karthikeyan Kandasamy
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • 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
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
for JRE i believe no difference between marker and other interface.....
 
Matthew Brown
Bartender
Posts: 4566
8
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic