System的identityHashCode()

来源:互联网 发布:python turtle 坐标 编辑:程序博客网 时间:2024/06/07 01:35
//对象的identityHashCode()相同,一定是相等的对象
public class IdentityHashCodeDemo {


public static void main(String[] args) {

String str1 = new String("Hello World");
String str2 = new String("Hello World");
System.out.println(str1.equals(str2));//true
System.out.println(str1.hashCode()==str2.hashCode());//true
System.out.println(System.identityHashCode(str1)+"====="+System.identityHashCode(str2));//值不同

String str3="Java学习之法";
String str4="Java学习之法";
System.out.println(System.identityHashCode(str3)+"====="+System.identityHashCode(str4));//值相同
}
}
0 0
原创粉丝点击