Versions Compared

Key

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

...

Unfortunately, in this case it is impossible to extend the Card class by adding a value or field in the subclass while preserving the equals() contract. Use This problem is not specific to the Card class, but applies to any class hierarchy that can consider equal instances of distinct subclasses of some superclass. For such cases, use composition rather than inheritance to achieve the desired effect [Bloch 2008]. This compliant solution adopts this approach by adding a private card field to the XCard class and providing a public viewCard() method.

...

MITRE CWE

CWE-697. Insufficient comparison

Bibliography

[API 2006]

Method equals()

[Bloch 2008]

Item 8. Obey the general contract when overriding equals

[Darwin 2004]

9.2, Overriding the equals Method

[Harold 1997]

Chapter 3, Classes, Strings, and Arrays, The Object Class (Equality)

[Sun 2006]

Determining If Two Keys Are Equal (JCA Reference Guide)

[Techtalk 2007]

More Joy of Sets

...