aspose file tools
The moose likes Java in General and the fly likes implements java.util.Comparator Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "implements java.util.Comparator" Watch "implements java.util.Comparator" New topic
Author

implements java.util.Comparator

walter wang
Ranch Hand

Joined: Jun 02, 2001
Posts: 144
Hello All,

As we know java.util.Comparator
is a inteface which has two methods decalration
one is compare
another is equals

MyCyComparator implements method compare, doesnot implement
method equals.
Supprisingly, It compiled and runs smoothly

Why?


class MyComparator implements Comparator{
public int compare(Object o1, Object o2) {
Integer integer1=(Integer)o1;
Integer integer2=(Integer)o2;
return -integer1.compareTo(integer2);
}
}


public class Walter{
public boolean is_Working_Now(boolean is_boss_Coming){
return is_boss_Coming;
}
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8263

All java objects are subclasses of java.lang.Object which has an implementation of equals. The reason that Comparator declares equals is to remind you that the behavior of compare and equals should compliment each other (i.e. things which return 0 for compare should return true for equals). More info in the Java Documentation.


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: implements java.util.Comparator
 
Similar Threads
Regarding Comparator and Comparable interfaces
Collection sort
Comparator
Sort by Name
"==" and Number-Wrappers