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(这个)代码>,也请参考关于“超级类”调用的公认答案(如果您也考虑使用其他方法执行此操作):