Currency does not override
the method Object.equals, the expression
x.equals(y) uses Object.equals
which checks the references x and
y for equality. That is,
x.equals(y) is true iff
x and
y reference the same object.
Therefore, when
x and
y reference equal but different instances of
Currency,
x.equals(y) is false.
The method applications.CurrencyWithEquals.equals
which checks two instances for equality is given below.
/** @return true iff this and theCurrency are equal */
public boolean equals(CurrencyWithEquals theCurrency)
{return (getSign() == theCurrency.getSign() &&
getDollars() == theCurrency.getDollars() &&
getCents() == theCurrency.getCents());}