Java Java API
java.lang.System
public static int identityHashCode(Object x)
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().
package com.logicbig.example.system;public class IdentityHashCodeExample { public static void main(String... args) { String str = "testString"; System.out.println(System.identityHashCode(str)); }}
256338459
package com.logicbig.example.system;public class IdentityHashCodeExample2 { public static void main(String... args) { MyClass myClass = new MyClass(20); int i = myClass.hashCode(); System.out.println(i); int i2 = System.identityHashCode(myClass); System.out.println(i2); } private static class MyClass { private int i = 0; public MyClass(int i) { this.i = i; } @Override public int hashCode() { return i; } }}
20817118299