Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calling Object implementation of hashCode [duplicate]

Tags:

java

hashcode

I have a hierarchy like this:

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;
    }
}

I want b.hashCode() to return the Object implementation of hashCode(). Unfortunately B has to extend A, and A can't change.

like image 596
zelinka Avatar asked Feb 27 '26 18:02

zelinka


1 Answers

Just return System.identityHashCode(this).

like image 193
jason Avatar answered Mar 01 '26 07:03

jason



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!