主要是说一下 equals 和 hashcode
1.hashCode
2.equals 5.对于 non-null reference x ,满足 x.equals(x) return true。 5. 对于 non-null reference x,y 满足 对称性 即:如果 x.equals(y) return true ,则 y.equals(x) 也会 return true 。 6. 对于 non-null reference x,y,x 满足 传递性。即:如果 x.equals(y) return true 和 y.equals(z) return true,那么 x.equals(z) 也应该 return true 。 7. 对于任何 non-null reference x,y,满足一致性,x.equals(y) 要是 true永远是true 8. 对于任何 non-null reference x, x.equals(null) return false. 9. 当重写 equals 方法是必须需要重写 hashCode,这样才能保证 equals 为true的两个对象的 hashCode也一样。(jre 中就有违背这条的类存在)
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有