Enhanced Enums -- use cases

Brian Goetz brian.goetz at oracle.com
Tue Apr 11 19:11:18 UTC 2017

As you may have noticed, we pushed an implementation of Enhanced Enums 
some time ago.  We're hoping to get user feedback on the feature as it 
is now implemented.

To get things started, here are some typical use cases where generic 
enums might be useful.  Please contribute others, as well as places in 
the JDK where code could be refactored using this feature.

An obvious example is com.sun.tools.javac.code.Dynamic 
where we have an enum that represents the kinds of types representable 
in the constant pool.

In that case, these factory methods:

should be collapsible to a single generic method:

     <D> static BootstrapArgument<D> constant(Kind<D> kind, D data).

Another example is command line parsing; for command line arguments, we 
can represent them as enums whose type represents the type of an 
(optional) parameter:

     enum Args {
         QUIET<??>("quiet", "q"),
         FILE<String>("file", "f"),
         COUNT<Integer>("count", "c"), ....

(though its not obvious what the type arg of QUIET should be.)

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....

More information about the amber-dev mailing list