2. The implementation of equals for the Date Value class.

Listing 2. The implementation of equals for the Date Value class.


public final class Date ...
{
    ...
    public boolean equals(Object rhs)
    {
        return rhs instanceof Date && equals((Date) rhs);
    }
    public boolean equals(Date rhs)
    {
        return rhs != null && rhs.year == year &&
               rhs.month.equals(month) && rhs.day == day;
    }
    private int year, day;
    private Month month;
}

About the Author

Kevlin Henney is a Principal Technologist with QA Training in the UK.