Java Hash Code Calculate hashCode(Object obj)

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

Description

Gets the hash code of an object returning zero when the object is null.

 ObjectUtils.hashCode(null)   = 0 ObjectUtils.hashCode(obj)    = obj.hashCode() 

License

Apache License

Parameter

Parameter Description
obj the object to obtain the hash code of, may be <code>null</code>

Return

the hash code of the object, or zero if null

Declaration

public static int hashCode(Object obj) 

Method Source Code

//package com.java2s;

public class Main {
    /**//  w  ww  .  j av a2 s  . c  o  m
     * <p>Gets the hash code of an object returning zero when the
     * object is <code>null</code>.</p>
     *
     * <pre>
     * ObjectUtils.hashCode(null)   = 0
     * ObjectUtils.hashCode(obj)    = obj.hashCode()
     * </pre>
     *
     * @param obj  the object to obtain the hash code of, may be <code>null</code>
     * @return the hash code of the object, or zero if null
     * @since 2.1
     */
    public static int hashCode(Object obj) {
        return (obj == null) ? 0 : obj.hashCode();
    }
}

Related

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