Java.lang.System.identityHashCode() Method
Advertisements
Description
The java.lang.System.identityHashCode() method returns the same hash code for the given object as would be returned by the default method hashCode(). The hash code for the null reference is zero.
Declaration
Following is the declaration for java.lang.System.identityHashCode() method
public static int identityHashCode(Object x)
Parameters
x -- This is the object for which the hashCode is to be calculated.
Return Value
This method returns the hashCode.
Exception
NA
Example
The following example shows the usage of java.lang.System.identityHashCode() method.
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);
}
}
Let us compile and run the above program, this will produce the following result:
355165777 1414159026 1569228633