4. A Class Factory Method that converts from int to Month.

Listing 4. A Class Factory Method that converts from int to Month.


public final class Month ...
{
    ...
    public static Month valueOf(int month)
        { return months[month - 1]; }
    private static final Month[] months =
        { january, ..., december };
    ...
}

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.