Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<blockquote> <p>I need to keep an unique ID for each object that I'm using, that's why I decided to use the IdentityHashCode, as far as I understand, this value is the same through the compilation.</p> </blockquote> <p>No. It's got nothing to do with compilation, and it's <em>not</em> guaranteed to be unique.</p> <p>It's not clear what you're trying to do, but you simply shouldn't regard hash codes as unique - they're not guaranteed to be.</p> <p>The <code>Object.hashCode</code> documentation specifies:</p> <blockquote> <p>As much as is reasonably practical, the hashCode method defined by class Object does return distinct integers for distinct objects.</p> </blockquote> <p>That's not the same thing as guaranteeing it though.</p> <p>You're <em>also</em> being confused by the result of calling <code>toString()</code> - I suspect your class actually overrides <code>hashCode()</code>, and <code>Object.toString()</code> calls the potentially-overridden <code>hashCode()</code> method rather than using the identity hash code:</p> <blockquote> <p>The toString method for class Object returns a string consisting of the name of the class of which the object is an instance, the at-sign character `@', and the unsigned hexadecimal representation of the hash code of the object. In other words, this method returns a string equal to the value of:</p> <pre><code>getClass().getName() + '@' + Integer.toHexString(hashCode()) </code></pre> </blockquote> <p>If you call <code>obj.hashCode()</code> you'll see the same value that's shown by <code>toString</code>.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload