Object.hashCode() のデフォルトの動作は、a == b の場合に限り、a.hashCode() == b.hashCode() となるように、本質的にオブジェクトの「アドレス」を返すことです。スーパークラスが既に hashCode() を定義している場合、ユーザー定義クラスでこの動作を取得するにはどうすればよいですか? 例えば:
class A {
public int hashCode() {
return 0;
}
}
class B extends A {
public int hashCode() {
// Now I want to return a unique hashcode for each object.
// In pythonic terms, it'd look something like:
return Object.hashCode(this);
}
}
アイデア?