or "Why do the Sun/Oracle guys force us to override both equals() and hashCode() everytime?"
Everyone knows that, if you override equals() or hashCode() of an object, you have to override the other one, too, because there is a contract between those two:
Note that it is generally necessary to override the hashCode method whenever this method [i.e. equals()] is overridden, so as to maintain the general contract for the hashCode method, which states that equal objects must have equal hash codes. -- API doc of Object.equals()
Why isn't it implemented that way in the Object class:
public boolean equals(Object obj) {
return this.hashCode() == obj.hashCode()
}
If they did this, it would have saved the rest of the world from having to implement both methods. It would be enough to override only hashCode().
I guess the guys had some good reason not to do this. I just cannot see it - please clear this up for me.