【问题标题】:Calling Object implementation of hashCode [duplicate]hashCode的调用对象实现[重复]
【发布时间】:2013-08-06 18:57:51
【问题描述】:

我有这样的层次结构:

public class A {
    public abstract int hashCode();
}
public class B extends A {
    public int hashCode(){
        //I want this to return the object implementation of hash code
        return 0;
    }
}

我希望 b.hashCode() 返回 hashCode() 的 Object 实现。不幸的是 B 必须扩展 A,而 A 不能改变。

【问题讨论】:

    标签: java hashcode


    【解决方案1】:

    【讨论】:

    • 酷,谢谢,这行得通。除非我在 15 分钟内无法接受这个答案。
    • 漂亮。我本来打算提出一些丑陋的解决方法,但当然,如果已经有一些东西可以做到......
    • 除了System.identityHashCode(this);,还请参考关于“超超类”调用的公认答案(如果您也想用不同的方法来做这件事):super super class method invocation
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-01-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-07
    相关资源
    最近更新 更多