Value type hash code

Dan Smith daniel.smith at
Wed Apr 11 14:13:51 UTC 2018

> On Apr 10, 2018, at 8:49 AM, David Simms <david.simms at> wrote:
> * Values containing references whose contents are mutable pose a
>   problem, their hash code is only as stable as the contents of the
>   whole object graph.

There's some flexibility in how we name operations, but let's observe that there are two pairs of operations to consider:

substitutable/substitutableHash: recur on value fields, use acmp on reference fields
deepEquals/deepHash: recur on value fields, use 'equals' on reference fields

I think my expectation has been that substitutable/substitutableHash would be the default behavior of equals/hashCode, with the capability for users to override this if they're confident it's safe. (And with the ability to fall back to the default behavior with System.identityHashCode or something similar.)


More information about the valhalla-dev mailing list