According to the documentation,
The identity hash code of
object
.
Returns the value that the original
Object.hashCode
would return on this object, even ifhashCode
has been overridden.
This hash code is compatible with
identical
, which means that it’s guaranteed to give the same result every time it’s passed the same argument, throughout a single program execution, for any non-record object.
However, it seems not quite compatible with identical
(whatever compatible means): the program
void main() {
print(identityHashCode(0));
print(identityHashCode(null));
print(identical(null, 0));
}
prints
0
0
false
Interestingly, null
and 0
have the same zero identityHashCode, and identityHashCode
cannot always be used as a proxy for identical
.