Versions Compared

Key

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

...

The cause of this erroneous behavior is that the CreditCard class overrides the equals() method but fails to override the hashCode() method. Consequently, the default hashCode() method returns a different value for each object, even though the objects are logically equivalent; these differing values lead to examination of different buckets in the hash bucketstable, which prevents the get() method from finding the intended value.
Note that by specifying the credit card number in main(), these code examples violate rule MSC03-J. for the sake of brevity.

...

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="149dac2827ce2f0e-980f5a59-4d5d408d-8180be63-18bfa9f7688b2e55cde710cb"><ac:plain-text-body><![CDATA[

[[API 2006

AA. References#API 06]]

[Class Object

http://java.sun.com/javase/6/docs/api/java/lang/Object.html]

]]></ac:plain-text-body></ac:structured-macro>

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="94680acad9cba8b1-1071e530-482d423b-b26e825e-d09fc3e3a25ae7d7bdf6302a"><ac:plain-text-body><![CDATA[

[[Bloch 2008

AA. References#Bloch 08]]

Item 9. Always override hashCode when you override equals

]]></ac:plain-text-body></ac:structured-macro>

...