I would assume that NSObject
isEquals
uses the ==
operator, and hash
uses the memory address.
isEquals
method should never uses hash
as an absolute test for equality. It is guaranteed to have two objects having similar hashCode
, if you search for enough objects (just create more than 2^32 different objects, and at least two of them will have the same hash
).
In other words, hash
requires the following spec: If two objects are equals, then their hash
needs to be equal; however, if two objects' hash
values are equals, they are not necessarily equal.
As a tip, you always should override isEquals
and hashCode
together.
一言以蔽之,两个NSObject对象相等,它们的HashCode一定相等。但是反过来不成立。