The equals method is part of the interface. It overrides the one inherited from Object. You can write your own implementation of equals. But you won't get a compile-time error if you don't override it with your own.
Originally posted by Keith Lynn: The equals method is part of the interface. It overrides the one inherited from Object.
Technically, that statement's not quite right. The interface does not "override" the equals() method from Object. Rather, it simply mandates that any object that implements Comparator must provide an equals() method. However, since Object already has an appropriate equals() method, no other class ever has to provide its own implementation of equals() to satisfy the Comparator interface.
Why, then, does Comparator specify an equals() method? You'll have to ask the original designers for the complete answer, but the Javadocs imply that this was just to draw programmers' attention to this recommendation:
public boolean equals(Object obj)
Indicates whether some other object is "equal to" this Comparator. This method must obey the general contract of Object.equals(Object). . . . Note that it is always safe not to override Object.equals(Object). However, overriding this method may, in some cases, improve performance by allowing programs to determine that two distinct Comparators impose the same order.
Joined: Feb 07, 2005
Sorry. I didn't meant to confuse. I was using overrides in the sense that the javadocs do.