两个对象的 hashCode()相同,则 equals()也一定为 true,对吗?
If two objects have the same hashCode(), does that mean equals() must be true?
题目类型: 技术面试题
这是一道技术面试题,常见于澳洲IT公司面试中。
难度: easy
分类: Java
标签: hashCode, equals, Collision
参考答案摘要
答案 不对,两个对象的 hashCode()相同,equals()不一定 true。 代码示例: String str1 = "通话"; String str2 = "重地"; System.out.println(String.format("str1:%d | str2:%d", str1.hashCode(),str2.hashCode())); System.out.println(str...
本题提供 STAR 原则详细解答和技术解析,登录匠人学院学习中心即可查看完整答案。