如果你能清除我的疑问,我将非常感激假设我有一个 A 类和 B A 有 B 的参考,比如 b1 和 b2。就像在类 A 中一样,重写了类似 b1.equal(other.b1) 和 b2.equal(other.b2) 的方法
并覆盖哈希码方法,例如
int result = 1;
result = 17* result + ((b1== null) ? 0 : b1.hashCode());
result = 17* result + ((b2== null) ? 0 : b2.hashCode());
return result;
我的哈希码方法是否正确实施?如果我调用 b1.hashcode() 那么它也会调用 B 类的 hashcode 方法吗?如果是,那么是否必须覆盖 B 类中的等号和哈希码?
提前致谢。