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.

Upcoming Training Events

0 AM
Visual Studio Live! San Diego
September 8-12, 2025
Live! 360 Orlando
November 16-21, 2025
Cloud & Containers Live! Orlando
November 16-21, 2025
Data Platform Live! Orlando
November 16-21, 2025
Visual Studio Live! Orlando
November 16-21, 2025