Java Object Hash hashCode(Object o)

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

Description

Return a proper hashCode for the given object.

License

LGPL

Parameter

Parameter Description
o the object

Return

a hash code for the object

Declaration

public static int hashCode(Object o) 

Method Source Code

//package com.java2s;
//License from project: LGPL 

import java.util.*;

public class Main {
    /**/*www .  j  a  v  a  2  s . c  o m*/
     * <p>Return a proper hashCode for the given object. If the object is an array, the appropriate hashCode method in
     * the {@link Arrays} class will be called.</p>
     * @param o the object
     * @return a hash code for the object
     */
    public static int hashCode(Object o) {
        if (o instanceof boolean[]) {
            return Arrays.hashCode((boolean[]) o);
        } else if (o instanceof byte[]) {
            return Arrays.hashCode((byte[]) o);
        } else if (o instanceof short[]) {
            return Arrays.hashCode((short[]) o);
        } else if (o instanceof char[]) {
            return Arrays.hashCode((char[]) o);
        } else if (o instanceof int[]) {
            return Arrays.hashCode((int[]) o);
        } else if (o instanceof long[]) {
            return Arrays.hashCode((long[]) o);
        } else if (o instanceof float[]) {
            return Arrays.hashCode((float[]) o);
        } else if (o instanceof double[]) {
            return Arrays.hashCode((double[]) o);
        } else if (o instanceof Object[]) {
            return Arrays.deepHashCode((Object[]) o);
        } else {
            return Objects.hashCode(o);
        }
    }
}

Related

  1. hash(Object... objects)
  2. hash(Object... values)
  3. hashCode(final Object o)
  4. hashCode(final Object... objects)
  5. hashCode(final Object... objects)
  6. hashCode(Object obj)
  7. hashCode(Object obj)
  8. hashCode(Object object)
  9. hashCode(Object... args)