Java Hash Code Calculate hashCode(Object a)

Here you can find the source of hashCode(Object a)

Description

Get the hashCode of an object.

License

Open Source License

Return

an optimized version of a == null ? 0 : a.hashCode().

Declaration

public static final int hashCode(Object a) 

Method Source Code

//package com.java2s;

public class Main {
    /**//from  w ww  .j  a v a2  s  .  c om
     * Get the hashCode of an object.
     * <p>
     * This method is just a shortcut to simplify assertion statements.</p>
     * @return an optimized version of a <span class="operator">==</span> <span class="keyword">null</span> <span class="operator">?</span> 0 <span class="operator">:</span> a.hashCode().
     * @see #equals(Object, Object)
     */
    public static final int hashCode(Object a) {
        try {
            return a.hashCode();
        } catch (NullPointerException ex) {
            //@internal possibly quicker variant to explicit prechecks for null: simply let this exceptional case occur, and then handle it.
            if (a == null) {
                return 0;
            } else {
                // another cause for the NullPointerException than null arguments
                throw ex;
            }
        }
    }
}

Related

  1. hashCode(long a[])
  2. hashCode(long longVal)
  3. hashCode(long value)
  4. hashCode(long x)
  5. hashCode(long[] a, int fromIndex, int toIndex)
  6. hashCode(Object array)
  7. hashCode(Object o)
  8. hashCode(Object o)
  9. hashCode(Object o)