Java.lang.System.identityHashCode() 方法
描述
java.lang.System.identityHashCode() 方法为给定对象返回与默认方法 hashCode() 返回相同的哈希码。 空引用的哈希码为零。
声明
以下是 java.lang.System.identityHashCode() 方法的声明。
public static int identityHashCode(Object x)
参数
x − 这是要为其计算 hashCode 的对象。
返回值
此方法返回 hashCode。
异常
NA
示例
下面的例子展示了 java.lang.System.identityHashCode() 方法的使用。
package com.tutorialspoint;
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

