Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/307.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java hashCode的调用对象实现_Java_Hashcode - Fatal编程技术网

Java hashCode的调用对象实现

Java hashCode的调用对象实现,java,hashcode,Java,Hashcode,我有这样的层次结构: 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()的对象实现

我有这样的层次结构:

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()的对象实现。不幸的是,B必须扩展A,而A不能更改。

只需返回。

很酷,谢谢,这很有效。不过我15分钟内都不能接受这个答案。我打算提出一些丑陋的解决方法,但当然,如果已经有什么东西可以做到这一点……除了
System.identityHashCode(这个),也请参考关于“超级类”调用的公认答案(如果您也考虑使用其他方法执行此操作):