aspose file tools*
The moose likes Java in General and the fly likes Comparable/Comparator query Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Comparable/Comparator query" Watch "Comparable/Comparator query" New topic
Author

Comparable/Comparator query

jose chiramal
Ranch Hand

Joined: Feb 12, 2010
Posts: 266
In my code the class ComparatorTest doesn't implement Comparable interface but provides implementation for the compareTo method, how is this possible ??

The class firstNameComparator however implements Comparator.

David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

jose chiramal wrote:In my code the class ComparatorTest doesn't implement Comparable interface but provides implementation for the compareTo method

No it doesn't.

In any case, a class can define any method it wants--that doesn't mean it implements an interface that defines that method.
jose chiramal
Ranch Hand

Joined: Feb 12, 2010
Posts: 266
My mistake, in the above code


class Person implements Comparable

Am all set.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Comparable/Comparator query