...
In this compliant solution, the CaseInsensitiveString.equals()
method is simplified to only operation operate on instances of the CaseInsensitiveString
class.
...
In the noncompliant code example, p1
and p2
compare equal and p2
and p3
compare equal but p1
and p3
compare unequal; violating the transitivity requirement. The problem is that the Card
class has no knowledge of the XCard
class and consequently cannot determine that p2
and p3
have different values for the field type
. Unfortunately, it is impossible to extend an instantiable class (as opposed to an abstract
class) by adding a value or field in the subclass while preserving the equals()
contract.
...