I'm currently studying the Comparator
interface and noticed that in the documentation for Comparator's equals method, it states
Note that it is always safe not to override Object.equals(Object)
I have checked the implementation for the default equals
method in Object
class
So with the default implementation of equals
method, it simply checks whether two instances points to the same object because this == obj
tests for reference equality.
But what happen if I have two instances of Comparator
, the result they return are identical, and I want to know if they are equivalent. If I dont override the default Object's equals
method, then regardless of whether the result they return is equivalent or not, by using the default Object's equals
method, false
will always be returned. So is it still always safe not to override the Object.equals(Object)?