Java Hash Code Calculate hashCode(Object obj)

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

Description

Return a zero hashCode if the object is null, otherwise return the real hashCode

License

GNU General Public License

Parameter

Parameter Description
obj an object

Return

the hashCode, or zero if the object is null

Declaration

public static int hashCode(Object obj) 

Method Source Code

//package com.java2s;
/*//  ww w . j  ava  2 s.  c  om
 * Copyright (C) 2002-2017 FlyMine
 *
 * This code may be freely distributed and modified under the
 * terms of the GNU Lesser General Public Licence.  This should
 * be distributed with the code.  See the LICENSE file for more
 * information or http://www.gnu.org/copyleft/lesser.html.
 *
 */

public class Main {
    /**
     * Return a zero hashCode if the object is null, otherwise return the real hashCode
     *
     * @param obj an object
     * @return the hashCode, or zero if the object is null
     */
    public static int hashCode(Object obj) {
        if (obj == null) {
            return 0;
        }
        return obj.hashCode();
    }
}

Related

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