Why don’t we let JVM take it? I understand we need override toString()
to keep consistency in Kotlin world. But for hashCode and equals?
1 Like
The only reason I can think of for hashCode()
is to have consistent implementation across target platforms, but I don’t see why anyone would need that Probably it was not yet done.
3 Likes
Changing the hash implementation would be a breaking change for code which relies on binary serialization of a HashMap (and other hash dependant classes).
- hash map is serialized and stored in a database
- kotlin updated, hash codes of objects change
- hash map is fetched from a database and deserialized but it’s corrupted and values are inaccessible.
1 Like
Storing hash codes anywhere doesn’t sound like a good idea. Documentation says explicitly there are no guarantees for it to be consistent, even if using the same codebase in same versions:
This integer need not remain consistent from one execution of an application to another execution of the same application.
2 Likes
Yes it’s bad but I have seen things.
1 Like