If two objects are equal then they should must have the same hashcode but the reverse is not true (i.e. If two objects have the same hashcode does not mean that they are equal)
But my question is why the reverse has not
If two objects are equal then they should must have the same hashcode but the reverse is not true (i.e. If two objects have the same hashcode does not mean that they are equal)
But my question is why the reverse has not given priority.
Same hashcode means same hash bucket. You put object which are equals to the same bucket know?
As you've stated, same hashCode means same bucket - so, if two objects have same hashCode, this simply means that those objects belong to same bucket. Now, these two objects may be different (i.e. not equal). Thus, if hashCode of two objects are same, doesn't mean that those objects are equal.
Imagine you park your car in a large parking structure with many levels. You make a mental note that you parked on level J. You leave the parking structure for a couple hours, then come back and now it's time to find your car. You don't know exactly where it is, but you remember it's on level J. You go to level J, and start walking down the rows of cars until you find your own. There are many cars on level J, but they're not all equal to yours, so you have to look at them one by one until you find yours. But because you knew it w