Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Even when the equals() method conveys logical equivalence between classes, the hashCode() method returns distinct numbers as opposed to returning the same values, as expected by the contract. This noncompliant code example stores a credit card number into a HashMap and retrieves it. The expected retrieved value is Java, however, null is returned instead. The reason for this erroneous behavior is that the hashCode method is not overridden which means that a different bucket would be looked into than was the one used to store the original value.

...