Java Hash Code Calculate hashCode(Object o)

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

Description

Returns the hash code of the object, handling |null|.

License

Open Source License

Declaration

public static int hashCode(Object o) 

Method Source Code

//package com.java2s;
// Use of this source code is governed by a BSD-style license that can be

public class Main {
    /**//from  w ww  .  j  av a 2s.  c  o m
     * Returns the hash code of the object, handling |null|.
     */
    public static int hashCode(Object o) {
        if (o == null) {
            return 0;
        }
        return o.hashCode();
    }

    /**
     * Returns the hash code of the value.
     */
    public static int hashCode(boolean o) {
        return o ? 1231 : 1237;
    }

    /**
     * Returns the hash code of the value.
     */
    public static int hashCode(long o) {
        return (int) (o ^ (o >>> 32));
    }

    /**
     * Returns the hash code of the value.
     */
    public static int hashCode(float o) {
        return Float.floatToIntBits(o);
    }

    /**
     * Returns the hash code of the value.
     */
    public static int hashCode(double o) {
        return hashCode(Double.doubleToLongBits(o));
    }

    /**
     * Returns the hash code of the value.
     */
    public static int hashCode(int o) {
        return o;
    }
}

Related

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