首页  

hashCode和identifyHashCode区别     所属分类 java 浏览量 1140
System  identifyHashCode(Object o)
返回指定对象的精确hashCode,根据对象的地址计算得到
某个类的hashCode()方法被重写之后,该类实例的hashCode()的方法不能唯一标识该对象

两个对象的identifyHashCode()相同,肯定是同一个对象

HashCode 和 identifyHashCode 的关系

对象的hashCode()一般通过将对象的内部地址转换成一个整数来实现
hashCode 可以重写 ,
null调用hashCode()方法 空指针 ,但是System.identifyhashCode(null)返回0


		
String s1 = new String("hello");
String s2 = new String("hello");		
String s3 = s2;
// false
System.out.println(s1==s2);
// true
System.out.println(s1.equals(s2));
// true
System.out.println(s2==s3);

System.out.println(s1.hashCode()+","+System.identityHashCode(s1));
System.out.println(s2.hashCode()+","+System.identityHashCode(s2));
System.out.println(s3.hashCode()+","+System.identityHashCode(s3));

// 0
System.out.println(System.identityHashCode(null));

上一篇     下一篇
tomcat 热加载 热部署

arthas 使用 ognl 设置日志级别

ThreadLocal 与 SimpleDateFormat

clickhouse表引擎

clickhouse SQL

clickhouse基础