<html><body><div style="font-family: arial, helvetica, sans-serif; font-size: 12pt; color: #000000"><div><br></div><div><br></div><hr id="zwchr" data-marker="__DIVIDER__"><div data-marker="__HEADERS__"><blockquote style="border-left:2px solid #1010FF;margin-left:5px;padding-left:5px;color:#000;font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt;"><b>From: </b>"Pedro Lamarão" <pedro.lamarao@prodist.com.br><br><b>To: </b>"valhalla-dev" <valhalla-dev@openjdk.org><br><b>Sent: </b>Tuesday, February 27, 2024 3:49:00 PM<br><b>Subject: </b>Recursively comparing<br></blockquote></div><div data-marker="__QUOTED_TEXT__"><blockquote style="border-left:2px solid #1010FF;margin-left:5px;padding-left:5px;color:#000;font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt;"><div dir="ltr">Hello all!</div></blockquote><div><br></div><div>Hello,<br data-mce-bogus="1"></div><div><br data-mce-bogus="1"></div><blockquote style="border-left:2px solid #1010FF;margin-left:5px;padding-left:5px;color:#000;font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt;"><div dir="ltr"><br><div>In reviewing the latest edition of JEP 401, I came into language that made me a little confused.</div><br><div>In section "Identity-sensitive operations" we read:</div><br><div>"Fields with primitive types are compared by their bit patterns. Other field values—both identity and value objects—are recursively compared with ==."</div><br><div>Later, we read:</div><br><div>"Also note that the == operator does not perform a "deep equals" comparison on identity objects stored in fields (...)"<br><br><div>My understanding of value classes so far has been that value objects are compared as-if by &&-ing the ==s of its fields. This seems to me the meaning of identity object fields not being compared by some deep equals algorithm. However, earlier, the text says that identity objects are recursively compared with ==. But recursively means to me something similar to deep: one would "recurse into" the object`s own fields.</div><div><div><br class="gmail-Apple-interchange-newline">I am not a native english speaker. Am I reading this incorrectly? What is the intention of saying that other field values, including identity object fields, are recursively compared with ==?</div></div></div></div></blockquote><div><br></div><div>I do not think the spec is not clear but let's take an example<br data-mce-bogus="1"></div><div>value record Foo(int i, float f) { }<br data-mce-bogus="1"></div><div><br data-mce-bogus="1"></div><div>var foo1 = new Foo();</div><div>var foo2 = new Foo();<br data-mce-bogus="1"></div><div><br data-mce-bogus="1"></div><div>foo1 == foo2</div><div>  is equivalent to</div><div>bitpattern(foo1.i) == bitpattern((foo2.i) && bitpattern(foo1.f) == bitpattern(foo2.f)<br data-mce-bogus="1"></div><div><br data-mce-bogus="1"></div><div>All primitives are compared using their bitpattern, for an int, bitpattern is equivalent to ==, but for a float, bit pattern is Float.<code>floatToRawIntBits</code>().<br data-mce-bogus="1"></div><div><br data-mce-bogus="1"></div><div>Now, let say, there is a third component of type Object<br data-mce-bogus="1"></div><div>value record Foo(int i, float f, Object o) { }</div><div><br data-mce-bogus="1"></div><div>In that case, foo1 == foo2<div>  is equivalent to</div>bitpattern(foo1.i) == bitpattern((foo2.i) && bitpattern(foo1.f) == bitpattern(foo2.f) && foo1.o == foo2.o<br data-mce-bogus="1"></div><div><br data-mce-bogus="1"></div><div>So if 'o' is an identity object, like String, the address will be used and if 'o' is itself a value type, like Foo, then == becomes a recursive call.<br data-mce-bogus="1"></div><div><br data-mce-bogus="1"></div><div>Is it more clear ?<br data-mce-bogus="1"></div><div><br data-mce-bogus="1"></div><blockquote style="border-left:2px solid #1010FF;margin-left:5px;padding-left:5px;color:#000;font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt;"><div dir="ltr"><div><br><span class="gmail_signature_prefix">-- </span><br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div>Pedro Lamarão</div></div></div></div></div></blockquote><div><br></div><div>Rémi<br data-mce-bogus="1"></div><div><br data-mce-bogus="1"></div></div></div></body></html>