Test of equality (equals and hash code method)

前端 未结 6 1502
挽巷
挽巷 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:49

    Actually the idea is that when you implemente the equals method you should implement the hashCode method, and if a.equals(b) then a.hashCode() == b.hashCode(). Although there isn't anything in the Java compiler or Runtime that enforces this.

提交回复
热议问题