On Tue, 4 Aug 2026 15:13:39 GMT, Chen Liang <[email protected]> wrote:
>> The existing sentence in Object.equals is:
>>
>> "In other words, under the object equality equivalence relation, each
>> equivalence class only has a single element."
>>
>> This is at least misleading -- likely to be misinterpreted by readers --
>> and, depending on one's chosen frame of reference, incorrect.
>>
>> My goal is to end with a non-misleading and correct, short, replacement
>> statement.
>
> What's wrong with my suggestion to change the last fragment to:
>
> "each equivalence class only has a single *distinguishable* element."
We need to start with a domain—what is in the set of all instances?—before we
can talk about how many instances are in an equivalence class.
Echoing Joe's "frame of reference" comment: from one perspective, the domain
includes every encoding of an instance in memory. From another, the domain
collapses down to only one element for each distinguishable instance of the
class.
We can expect some/most readers to come at this from the first frame of
reference, which is why we softened some of the language in the JEP, etc., from
"the value objects are the same" to "the value objects are indistinguishable".
Maybe in your frame of reference's domain, you're counting two different
things, but there's no way to tell them apart, so `==` won't try to.
There's also an uncomfortable circularity in the second frame of reference, if
we use it to explain the equivalence classes of `==`: each set has a single
element because, tautologically, if there were two elements in the set, they
would be the same. (I'm rusty on this stuff, but I'll gesture vaguely at
Gödel's incompleteness theorems. We need some ground truth to build our
equivalence classes on top of.)
In the first frame of reference, "has only a single distinguishable element"
isn't quite saying the right thing. It's more like "all elements in the set are
indistinguishable". But we just said that.
I don't necessarily mind the phrasing in the PR. But it is a bit wordy, and the
old flow of the paragraph just doesn't quite work the way it was intended to
anymore. Maybe it would be better to rephrase the whole note, something like:
The {@code equals} method for class {@code Object} implements
the most discriminating possible equivalence relation on objects;
that is, for any non-null reference values {@code x} and
{@code y}, this method returns {@code true} if and only
if {@code x} and {@code y} are completely indistinguishable
({@code x == y} has the value {@code true}).
<p>
In other words, under the object equality equivalence relation, each
equivalence class only has a single identity object, or a set
of value objects that instantiate the same class with the same
field values.
(I cheated a little by adopting John's "the same" for field values at the end.
The more formal way to say it is "with indistinguishable field values", but I
think "the same" reads more smoothly. We're not defining `==` here, just
reminding readers how it works.)
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/32158#discussion_r3716564878