Enums add type safety to finite and predefined sets of constants. Enums enable you to define a new type (such as a class or an interface) with a state and behavior. Project Amber is enhancing enums, taking them to the next level by adding type variables (generics) and allowing sharper enum type-checking. These will enable enums to define constants with type information, state, and behavior—applicable exclusively to each constant. These enhancements will reduce the need to refactor enums to classes in order to use generics.
In this chapter, we'll cover the following topics:
- The reason for enhancing enums
- Adding a state and behavior to enum constants
- Creating generic enums
- Accessing a constant, specific state and behavior
- Performing sharper type-checking for enum constants