Jumping in to note that this is a really big issue for the project I’m working on at the moment.
The project has a rather complex hierarchy of data classes (hundreds of them), all of which are immutable. Several of the data classes at the top of the hierarchy are stored in various
We’ve had to manually implement a caching version of
hashCode() for many of the data classes because calculating it every time was causing severe performance problems (the app was unusable).
This makes the code quite awkward to maintain, and prone to hard-to-find bugs (forgetting to include a newly added field in a hash calculation can cause bugs that go undetected for a long time, and only pop up in the field).
Data classes are great solution aside from this (this hierarchy of nested immutable data classes greatly simplifies concurrency during document updates between the UI and the render thread in the app, and also made it trivially easy to implement lightweight infinite-level undo; not to mention being the core of the architecture for editing documents synced across different app instances via the cloud).
It would be really really nice if it were possible to annotate a data class as immutable so we get a cached hashCode implementation automatically.