3

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.

zelinka
  • 3,271
  • 6
  • 29
  • 42

1 Answers1

13

Just return System.identityHashCode(this).

jason
  • 236,483
  • 35
  • 423
  • 525
  • Cool, thanks, that works. Except I can't accept this answer for 15 minutes. – zelinka Aug 05 '13 at 22:29
  • Nifty. I was going to suggest some ugly workaround, but of course, if there's already something that does it... – Dennis Meng Aug 05 '13 at 22:29
  • 1
    In addition to the `System.identityHashCode(this);`, also refer to the accepted answer in regards to "super super class" invocations (if you were thinking of doing this with a different method as well): [super super class method invocation](http://stackoverflow.com/questions/3456177/calling-super-super-class-method) – Pandacoder Aug 05 '13 at 22:31