Wednesday, April 12, 2017

Use Cases for Java Enhanced Enums

In the message Enhanced Enums -- use cases, Brian Goetz writes, "We're hoping to get user feedback on the feature [Enhanced Enums] as it is now implemented." He states the first purpose of his message, "To get things started, here are some typical use cases where generic enums might be useful." The first of the two presented examples is refactoring com.sun.tools.javac.code.Dynamic class and its eight factory methods returning different instances of BootstrapArgument with different instances of its nested Kind enum into a single method using the dynamic enum.

The second use case example of a possible application of enhanced enums that Goetz provides is command line parsing in which an enum is used to represent the data types of parameters. Vicente Romero replied to Goetz's message with two more examples of where enhanced enums might be applied: "code sharing between enum constants" and "the power of sharper typing".

Goetz encourages others to provide more use cases for enhanced enums, "Please contribute others, as well as places in the JDK where code could be refactored using this feature." He concludes, "If anyone wants to experiment and offer their experience in applying (or misapplying) this feature, either to the JDK or their own codebase, that would be appreciated...."

No comments: