wood burning stoves 2.0*
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Comparable/Comparator query
 
Similar Threads
Sort Arraylist by passing runtime parameter
Comparator Vs Comparable
Comparator and Comparable
Comparator and Comparable
Difference between Comparable and Comparator