鉴于这个前提:
输出结果为:
String s1= new String("abc");
String s2= new String("abc");
String s3 ="abc";
System.out.println(s1==s3);
System.out.println(s1==s2);
System.out.println(s1.equals(s2));
System.out.println(s1.equals(s3));
System.out.println(s1.hashCode());
System.out.println(s2.hashCode());
System.out.println(s3.hashCode());
输出结果为:
false
false
true
true
96354
96354
96354
这里每个对象都返回false,但每个String对象的哈希码是相同的。为什么会这样呢?