How to use typesafe enums in Java
Java code that uses traditional enumerated types is problematic. Java 5 gave us a better alternative in the form of typesafe enums. In this article, I introduce you to enumerated types and typesafe enums, show you how to declare a typesafe enum and use it in a switch statement, and discuss customizing a typesafe enum by adding data and behaviors. I wrap up the article by exploring the java.lang.Enum<E extends Enum<E>>
class.
From enumerated types to typesafe enums
An enumerated type specifies a set of related constants as its values. Examples include a week of days, the standard north/south/east/west compass directions, a currency’s coin denominations, and a lexical analyzer’s token types.