| 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]
|
 |
 |
|
|
subject: implements java.util.Comparator
|
|
|