Test of equality (equals and hash code method)

前端 未结 6 1501
挽巷
挽巷 2021-01-24 21:59

As per the below link

Hashcode and equals

So it is assumed that if 2 objects are equal (that is, equals() returns true), then their hashCodes() must retu

6条回答
  •  孤街浪徒
    2021-01-24 22:45

    You should never implement hashCode using random numbers! It should always be computed using the same fields as equals uses. Otherwise, your objects will be unusable as keys in HashMap, HashSet, etc.

提交回复
热议问题