Enhanced Enums -- use cases

Ali Ebrahimi ali.ebrahimi1781 at gmail.com
Wed Apr 12 06:42:51 UTC 2017


Hi,
Is not better we have an 'all-features' branch to play with all features
with one build?

On Tue, Apr 11, 2017 at 11:41 PM, Brian Goetz <brian.goetz at oracle.com>
wrote:

> 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 (
> http://hg.openjdk.java.net/valhalla/valhalla/langtools/file
> /85cc92a65da8/src/jdk.compiler/share/classes/com/sun/tools/
> javac/code/Dynamic.java#l51), where we have an enum that represents the
> kinds of types representable in the constant pool.
>
> In that case, these factory methods:
>
> http://hg.openjdk.java.net/valhalla/valhalla/langtools/file/
> 85cc92a65da8/src/jdk.compiler/share/classes/com/sun/tools/
> javac/code/Dynamic.java#l137
>
> 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....
>
>
>


-- 

Best Regards,
Ali Ebrahimi


More information about the amber-dev mailing list