编程技术网

关注微信公众号,定时推送前沿、专业、深度的编程技术资料。

 找回密码
 立即注册

QQ登录

只需一步,快速开始

极客时间

为什么具有相同哈希码的两个对象不一定相等?:Why two objects with the same hashcode are not necessarily equals?

lionblaze55 面向对象 2022-5-11 10:26 5人围观

腾讯云服务器
Currently I drilled into the JSE source code for fun. From some tutorials I found a principle two equals objects (i.e. as to object a and b a.equals(b) returns true) must have the same hashcode, on the other hand, two objects with the same hashcode are not necessarily equals. According to the HashTable source code of Java API (http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/6-b14/java/util/Hashtable.java), e.g. refer to line 254, we can almost derive equals => same hashcode, but I still can not fully understand why two objects with the same hashcode are not necessarily equals. Anyone can give more reasoning on this? Thanks in advance
腾讯云服务器 阿里云服务器
关注微信
^