Hacker News new | ask | show | jobs
by tsimionescu 36 days ago
The JEP itself highlights the problem of == leaking private details, and recommends avoiding its use in favor of equals(). It also highlights the potential security risk because of this, noting that private fields of value classes should not be considered secret because of this (and the new identityHash method).

The JEP also gives examples of classes where == would return false for instances that would behave exactly the same from an external perspective. They give examples mostly revolving around strings and other reference objects as fields of value objects; and some weirdness around float and double NaN. There's also the classical case of caching, where an object may store the inputs to a complex calculation, but can also cache the result of said calculation - and asking for the value can either perform the calculation, or return the cached result (though Java value classes don't fit this too well, given their limitations of being immutable).