If you strictly want a variable to assume a value within a specific set of constants, you should be better off with an enum.
In the above example, 'Color c' can take only four values(e.g. Color.RED, Color.YELLOW, Color.BLUE or Color.GREEN), whereas, in case of 'int color', nothing stops me from assigning any value outside the four static final int constants.
Stephan van Hulst
posted 8 years ago
You've already identified the most important advantage yourself.
It doesn't make sense for a Color to be 1 or 2 or 5. Colors should be RED or GREEN, etc. and there should be nothing else - like an integer value - that is of importance.
Enums provide this important distinction.
Whoever got anywhere by being normal? Just ask this exceptional tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop