目录

static int identityHashCode(Object x)

描述 (Description)

java.lang.System.identityHashCode()方法返回与默认方法hashCode()返回的给定对象相同的哈希码。 空引用的哈希码为零。

声明 (Declaration)

以下是java.lang.System.identityHashCode()方法的声明

public static int identityHashCode(Object x)

参数 (Parameters)

x - 这是要为其计算hashCode的对象。

返回值 (Return Value)

此方法返回hashCode。

异常 (Exception)

NA

例子 (Example)

以下示例显示了java.lang.System.identityHashCode()方法的用法。

package com.iowiki;
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
↑回到顶部↑
WIKI教程 @2018