假设我有一个类,它有许多实例变量,.我想重载==运算符(和hashCode),以便在映射中使用实例作为键.
class Foo {
int a;
int b;
SomeClass c;
SomeOtherClass d;
// etc.
bool operator==(Foo other) {
// Long calculation involving a, b, c, d etc.
}
}
比较计算可能很昂贵,所以在进行计算之前,我想判断other
是否与this
相同.
如何调用Object类提供的==运算符来执行此操作?