Versions Compared

Key

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

...

Typically, errors manifest when assumptions are made about the implementation specific details of the superclass. Here, the two objects are compared for equality in the overriding after() method and subsequently, the superclass's after() method is explicitly called to take over. The issue is that the superclass Calendar's after() method internally uses class Object's compareTo() method. Consequently, the superclass's after() method erroneously invokes the subclass's version of compareTo(). Because the subclass is unaware of the superclass's implementation of after(), it does not expect any of its own overriding methods to get invoked. The guideline MET32MET04-J. Ensure that constructors do not call overridable methods describes similar programming errors.

...