Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The <code>hashCode()</code> method is often used for identifying an object. I think the <code>Object</code> implementation returns the pointer (not a real pointer but a unique id or something like that) of the object. But most classes override the method. Like the <code>String</code> class. Two String objects have not the same pointer but they are equal:</p> <pre><code>new String("a").hashCode() == new String("a").hashCode() </code></pre> <p>I think the most common use for <code>hashCode()</code> is in <code>Hashtable</code>, <code>HashSet</code>, etc..</p> <p><a href="http://java.sun.com/javase/6/docs/api/java/lang/Object.html#hashCode()" rel="nofollow noreferrer">Java API Object hashCode()</a></p> <p><strong>Edit:</strong> (due to a recent downvote and based on an article I read about JVM parameters)</p> <p>With the JVM parameter <code>-XX:hashCode</code> you can change the way how the hashCode is calculated (see the <a href="http://www.javaspecialists.eu/archive/Issue222.html" rel="nofollow noreferrer">Issue 222</a> of the Java Specialists' Newsletter). </p> <blockquote> <p>HashCode==0: Simply returns random numbers with no relation to where in memory the object is found. As far as I can make out, the global read-write of the seed is not optimal for systems with lots of processors.</p> <p>HashCode==1: Counts up the hash code values, not sure at what value they start, but it seems quite high.</p> <p>HashCode==2: Always returns the exact same identity hash code of 1. This can be used to test code that relies on object identity. The reason why JavaChampionTest returned Kirk's URL in the example above is that all objects were returning the same hash code.</p> <p>HashCode==3: Counts up the hash code values, starting from zero. It does not look to be thread safe, so multiple threads could generate objects with the same hash code.</p> <p>HashCode==4: This seems to have some relation to the memory location at which the object was created.</p> <p>HashCode>=5: This is the default algorithm for Java 8 and has a per-thread seed. It uses Marsaglia's xor-shift scheme to produce pseudo-random numbers.</p> </blockquote>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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