Java Hash Code Calculate hashCode(Object obj)

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

Description

Returns the hashcode of obj considering that obj may be null.

License

Apache License

Parameter

Parameter Description
obj the obj to return the hashcode for

Return

the hashcode

Declaration

public static int hashCode(Object obj) 

Method Source Code

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

public class Main {
    /**/* ww w .  j  a va 2 s. co  m*/
     * Returns the hashcode of <code>obj</code> considering that <code>obj</code> may be <b>null</b>.
     * 
     * @param obj the obj to return the hashcode for
     * @return the hashcode
     */
    public static int hashCode(Object obj) {
        int result;
        if (null == obj) {
            result = 0;
        } else {
            result = obj.hashCode();
        }
        return result;
    }

    /**
     * Returns the hash code of the given boolean.
     * 
     * @param bool the boolean
     * @return the hash code
     */
    static int hashCode(boolean bool) {
        return bool ? 1 : 0;
    }
}

Related

  1. hashCode(Object o)
  2. hashCode(Object o)
  3. hashCode(Object o1, Object o2)
  4. hashCode(Object obj)
  5. hashcode(Object obj)
  6. hashCode(Object obj)
  7. hashCode(Object obj)
  8. hashCode(Object obj)
  9. hashCode(Object object)