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.

Featured

Most   Popular
Upcoming Events

AppTrends

Sign up for our newsletter.

Terms and Privacy Policy consent

I agree to this site's Privacy Policy.