<div dir="ltr"><div class="gmail_default" style="font-family:monospace">To respond to your actual point though, I think it would be great for identity classes to get this too.<br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Oct 18, 2023 at 7:18 PM David Alayachew <<a href="mailto:davidalayachew@gmail.com">davidalayachew@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_default" style="font-family:monospace">Potentially silly question in regards to the identityHashCode.</div><div class="gmail_default" style="font-family:monospace"><br></div><div class="gmail_default" style="font-family:monospace">Is it possible for an identityHashCode to produce a negative value?</div><div class="gmail_default" style="font-family:monospace"><br></div><div class="gmail_default" style="font-family:monospace">I tried the following, and it is still running. I don't have any window functions though, so I can't make arbitrary strings, just one character ones.</div><div class="gmail_default" style="font-family:monospace"><br></div><div class="gmail_default" style="font-family:monospace">$ jshell<br>|  Welcome to JShell -- Version 21<br>|  For an introduction type: /help intro<br><br>jshell> new java.util.Random()<br>   ...> .ints()<br>   ...> .filter(Character::isValidCodePoint)<br>   ...> .mapToObj(Character::toChars)<br>   ...> .map(String::new)<br>   ...> .mapToInt(System::identityHashCode)<br>   ...> .filter(a -> a < 0)<br>   ...> .findFirst()<br></div><div class="gmail_default" style="font-family:monospace"><br></div><div class="gmail_default" style="font-family:monospace">If the answer is, no negatives, then I think this would be best. I don't know if it would be "all value objects are -1", or something else.<br></div><div class="gmail_default" style="font-family:monospace"><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Oct 18, 2023 at 5:35 PM Archie Cobbs <<a href="mailto:archie.cobbs@gmail.com" target="_blank">archie.cobbs@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr">On Wed, Oct 18, 2023 at 3:59 PM Remi Forax <<a href="mailto:forax@univ-mlv.fr" target="_blank">forax@univ-mlv.fr</a>> wrote:</div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div><div style="font-family:arial,helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)"><br><div><blockquote style="border-left:2px solid rgb(16,16,255);margin-left:5px;padding-left:5px;color:rgb(0,0,0);font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt"><div dir="ltr">1. If v is a value object, what does System.identityHashCode(v) return?</div></blockquote><div><br></div><div>A combination of some field values of the object.<br></div><div>It has to be fast so the VM should not use all fields if there are a lot of them or if some values are value class (or field type that can potentially store value class) because it will make the computation recursive.</div></div></div></div></blockquote><div><br></div><div>Hmm, that doesn't seem right.</div><div><br></div><div>Isn't it <span style="font-family:monospace">hashCode()</span>'s job to produce a value based on the object's fields? The whole point of <span style="font-family:monospace">System.identityHashCode()</span><span style="font-family:arial,sans-serif"> is to NOT do that, at least as of today.<br></span></div><div><br></div><div>I'd expect <span style="font-family:monospace">System.identityHashCode()</span> to return 0 for all value classes or throw an exception.</div><div><br></div><div>After all, value classes are not supposed to have an identity, right?<br></div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div><div style="font-family:arial,helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)"><div><div><br></div><blockquote style="border-left:2px solid rgb(16,16,255);margin-left:5px;padding-left:5px;color:rgb(0,0,0);font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt"><div dir="ltr"><div>2. If V is a value class, is {Weak,Soft,Phantom}Reference<V> supported?</div></div></blockquote><div><br></div><div>Nope. There is maybe no address/no pointer so no weak reference.<br></div></div></div></div></blockquote><div><br></div>OK. How is this going to be enforced?</div><div class="gmail_quote"><br></div><div class="gmail_quote">-Archie<br clear="all"></div><br><span class="gmail_signature_prefix">-- </span><br><div dir="ltr" class="gmail_signature">Archie L. Cobbs<br></div></div>
</blockquote></div>
</blockquote></div>