/**
* Returns the same hash code for the given object as
* would be returned by the default method hashCode(),
* whether or not the given object's class overrides
* hashCode().
* The hash code for the null reference is zero.
*
* @param x object for which the hashCode is to be calculated
* @return the hashCode
* @since JDK1.1
*/
public static native int identityHashCode(Object x);
无论给定的x对象是否覆盖了hashCode()方法,都会调用默认的hashCode()方法返回hashCode,如果x == null, 返回0。
这个默认的hashCode()方法就是Object类中的hashCode方法。
public native int hashCode();
在其注释提到了一句:
This is typically implemented by converting the internal address of the object into an integer, but this implementation technique is not required by the Java™ programming language.
这说明默认的hashCode方法是根据对象的地址转换所得到的。
应用场景
fastJson中的IdentityHashMap类的get方法为获取key的hash值使用了这个方法。版本:1.1.33-android。