Chapter 8. Enhanced Enums in Project Amber
In Java 5, enums introduced a powerful way to define finite and predefined set of constants, with type safety. Enums enabled you to define a new type (like classes or interfaces) with state and behavior. Project Amber is enhancing enums, taking it to the next level; by adding type variables (generics) and allowing sharper type checking for enums. These two features will enable an enum to have constant specific type information and constant specific state and behavior. These enhancements will reduce the need of refactoring enums to classes, to use generics.
In this chapter, we'll cover the following topics:
- What is the reason for enhancing enums?
- Adding state and behavior to enum constants
- How to create generic enums?
- Accessing constant specific state and behavior
- Perform sharper type checking for enum constants
- Challenges