Avoid auto generate hashCode and equals when using @JvmRecord

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 :wink: Probably it was not yet done.


Changing the hash implementation would be a breaking change for code which relies on binary serialization of a HashMap (and other hash dependant classes).

  1. hash map is serialized and stored in a database
  2. kotlin updated, hash codes of objects change
  3. 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.


Yes it’s bad but I have seen things.

1 Like