RFR: 8289389: Fix warnings: type should also implement hashCode() since it overrides Object.equals() [v4]

Tom Schindl tschindl at openjdk.org
Thu Jul 21 12:33:22 UTC 2022


On Tue, 19 Jul 2022 19:55:34 GMT, John Hendrikx <jhendrikx at openjdk.org> wrote:

> I really must wonder at some of these changes. They seem... unnecessary. Just because equals is overridden, doesn't mean hashCode must be as well, especially not if the objects involved are mutable -- it might in fact be better to leave it alone or return a constant value from it (or only use immutable fields).

This not true - there's a contract between `hashCode` and `equals` quoting the JavaDoc of `hashCode()`:
> If two objects are equal according to the equals(Object) method, then calling the hashCode method on each of the two objects must produce the same integer result.

-------------

PR: https://git.openjdk.org/jfx/pull/821


More information about the openjfx-dev mailing list