Java Hash Code Calculate hashCode(final Object object)

Here you can find the source of hashCode(final Object object)

Description

Returns a hash code for an object, or zero if the object is null.

License

Open Source License

Parameter

Parameter Description
object the object (<code>null</code> permitted).

Return

The object's hash code (or zero if the object is null).

Declaration

public static int hashCode(final Object object) 

Method Source Code

//package com.java2s;
/*/*w w w .j  av  a2s.c  om*/
 * ========================================================================
 * JCommon : a free general purpose class library for the Java(tm) platform
 * ========================================================================
 * (C) Copyright 2000-2004, by Object Refinery Limited and Contributors.
 * Project Info: http://www.jfree.org/jcommon/index.html
 * This library is free software; you can redistribute it and/or modify it under the terms
 * of the GNU Lesser General Public License as published by the Free Software Foundation;
 * either version 2.1 of the License, or (at your option) any later version.
 * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU Lesser General Public License for more details.
 * You should have received a copy of the GNU Lesser General Public License along with this
 * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
 * Boston, MA 02111-1307, USA.
 * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
 * in the United States and other countries.]
 * ----------------
 * ObjectUtils.java
 * ----------------
 * (C) Copyright 2003, 2004, by Object Refinery Limited.
 * Original Author: David Gilbert (for Object Refinery Limited);
 * Contributor(s): -;
 * $Id: ObjectUtils.java,v 1.1 2011-01-31 09:01:41 klukas Exp $
 * Changes
 * -------
 * 25-Mar-2003 : Version 1 (DG);
 * 15-Sep-2003 : Fixed bug in clone(List) method (DG);
 */

public class Main {
    /**
     * Returns a hash code for an object, or zero if the object is <code>null</code>.
     * 
     * @param object
     *           the object (<code>null</code> permitted).
     * @return The object's hash code (or zero if the object is <code>null</code>).
     */
    public static int hashCode(final Object object) {
        int result = 0;
        if (object != null) {
            result = object.hashCode();
        }
        return result;
    }
}

Related

  1. hashCode(final long l)
  2. hashCode(final long l)
  3. hashCode(final long v)
  4. hashCode(final Object obj)
  5. hashCode(final Object obj)
  6. hashCode(final Object... array)
  7. hashCode(float value)
  8. hashCode(int base, int multiplier, boolean fastArrays, Object... relevantValues)
  9. hashCode(int currentHashCodeValue, boolean b)