Java System 類的 identityHashCode() 方法返回指定對象的哈希碼。它由默認方法 hashCode() 返回。
用法
public static int identityHashCode (Object x)
參數
x- 要為其計算 hashCode 的對象
返回
- 返回哈希碼。
- 如果哈希碼為空,則返回零作為參考。
例子1
public class SystemIdentityHashCodeExample1{
public static void main(String[] args) {
int a=10;
System.out.println("identity hash code of object a = "+System.identityHashCode(a));
int b=10;
System.out.println("identity hash code of object b = "+System.identityHashCode(b));
int c=01;
System.out.println("identity hash code of object c = "+System.identityHashCode(c));
}
}
輸出:
identity hash code of object a = 743673026 identity hash code of object b = 743673026 identity hash code of object c = 557722442
例子2
public class SystemIdentityHashCodeExample2{
public static void main(String[] args) {
String a=new String ();
a.equals("Shubham");
System.out.println("identity hash code of object a = "+System.identityHashCode(a));
String b=new String ();
b.equals("Jadon");
System.out.println("identity hash code of object b = "+System.identityHashCode(b));
}
}
輸出:
identity hash code of object a = 843730481 identity hash code of object b = 743673026
相關用法
- Java System inheritedChannel()用法及代碼示例
- Java System clearProperty()用法及代碼示例
- Java System loadLibrary()用法及代碼示例
- Java System console()用法及代碼示例
- Java System arraycopy()用法及代碼示例
- Java System exit()用法及代碼示例
- Java System getProperty()用法及代碼示例
- Java System setIn()用法及代碼示例
- Java System nanoTime()用法及代碼示例
- Java System getenv()用法及代碼示例
- Java System setErr()用法及代碼示例
- Java System load()用法及代碼示例
- Java System setOut()用法及代碼示例
- Java System lineSeparator()用法及代碼示例
- Java System setSecurityManager()用法及代碼示例
- Java System getSecurityManager()用法及代碼示例
- Java System getProperties()用法及代碼示例
- Java System gc()用法及代碼示例
- Java System setProperties()用法及代碼示例
- Java System mapLibraryName()用法及代碼示例
注:本文由純淨天空篩選整理自 Java System identityHashCode() Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。