%uA0java.lang.System.identityHashCode()%uA0方法返回给定对象的哈希代码会被默认使用方法hashCode()。空引用的哈希码返回是零。
声明
以下是java.lang.System.identityHashCode()方法的声明
public static int identityHashCode(Object x)
参数
-
x%uA0-- 这对于哈希码是待计算的对象。
返回值
此方法返回hashCode。
异常
-
NA
例子
下面的例子显示java.lang.System.identityHashCode()方法的使用。
package com.yiibai import java.lang.* import java.io.* public class SystemDemo { public static void main(String[] args) throws Exception { File file1 = new File("amit") File file2 = new File("amit") File file3 = new File("ansh") // returns the HashCode int ret1 = System.identityHashCode(file1) System.out.println(ret1) // returns different HashCode for same filename int ret2 = System.identityHashCode(file2) System.out.println(ret2) // returns the HashCode int ret3 = System.identityHashCode(file3) System.out.println(ret3) } }
让我们来编译和运行上面的程序,这将产生以下结果:
355165777 1414159026 1569228633