Hi,
As we know that we can override the hashCode() method of Object class with our own representation,What if i want to get the original hashCode() of a specific object. For that jdk provides a method inside of System class. Please go through the following example.
public class HashCodeDemo {
@Override
public int hashCode() {
return 20;
}
public static void main(String ar[]) {
HashCodeDemo hashObj = new HashCodeDemo();
System.out.println(hashObj);
System.out.println(hashObj.toString());
System.out.println(hashObj.hashCode());
System.out.println(System.identityHashCode(hashObj));
}
}
OutPut
--------
javaapplications.HashCodeDemo@14
javaapplications.HashCodeDemo@14
20
4072869
Thanks
Rajesh Kumar Yuvaraj
As we know that we can override the hashCode() method of Object class with our own representation,What if i want to get the original hashCode() of a specific object. For that jdk provides a method inside of System class. Please go through the following example.
public class HashCodeDemo {
@Override
public int hashCode() {
return 20;
}
public static void main(String ar[]) {
HashCodeDemo hashObj = new HashCodeDemo();
System.out.println(hashObj);
System.out.println(hashObj.toString());
System.out.println(hashObj.hashCode());
System.out.println(System.identityHashCode(hashObj));
}
}
OutPut
--------
javaapplications.HashCodeDemo@14
javaapplications.HashCodeDemo@14
20
4072869
Thanks
Rajesh Kumar Yuvaraj
No comments:
Post a Comment