想想String就知道,肯定是地址不是hash String a = new String("abc"); String b = new String("abc"); equals方法返回true的两个String hashcode是一样的,但是 ==是false啊,说明a.b指向的不是同一个对象,如果引用指向的是hash这就矛盾了
他们认为的hash肯定不是这个hash
String类型的ToString方法本重写过 我检测不出来啊
public class A { public static void main(String[] args) { Object obj = new Object(); System.out.println(obj); int value = System.identityHashCode(obj); System.out.println(Integer.toHexString(value)); String str = "hello"; System.out.println(System.identityHashCode(str)); } }
String a = new String("abc");
String b = new String("abc");
equals方法返回true的两个String hashcode是一样的,但是 ==是false啊,说明a.b指向的不是同一个对象,如果引用指向的是hash这就矛盾了
public class A { public static void main(String[] args) { Object obj = new Object();
System.out.println(obj);
int value = System.identityHashCode(obj);
System.out.println(Integer.toHexString(value));
String str = "hello";
System.out.println(System.identityHashCode(str));
}
}
Java中使用Hash code来区分对象,因而对象引用也是hash code了。
不是引用地址。引用对象地址的是C++的方法(&对象),不是java.