Yuriy Zubarev

Ominous hashCode() method

2010-03-05

I just spent couple of hours debugging a subtle problem only to pinpoint the root cause to an erroneous implementation of hashCode() method. It was a nice refresher in Java basics. Here is the culprit:

@Override
  public int hashCode() {
    return super.hashCode() + (this.code == null ? 0 : this.code.hashCode());
  }

Any guesses?

 

Comments :

blog comments powered by Disqus