Why we should always override hashCode() method whenever we override equals() method? As per my understanding they both seem to fulfill different purpose. hashCode() method is used in hashtables to determine the equality of keys. However equals() method is used to determine the equality of two objects.

有帮助吗?

解决方案

If two objects are equal according to the equals method, their hashcodes must be equal as well. Otherwise, lookup in the hash table would fail.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top