JEP 301: Enhanced Enums

Remi Forax forax at
Wed Dec 7 09:03:36 UTC 2016

I don't really like this proposal, it tries to resolve a corner case but breaks an important feature of the enum, the type of the values of an enum is the same as the enum.
Enums are a convenience feature, not something that should be used to design a hierarchy of types because, the hierarchy is closed and designing a hierarchy with an abstract base class is so 2000 .

We now have lambdas, so there is no reason to use 'abstract' enums anymore.
Instead of
  interface Activity {
      void perform();
  enum Activities implements Activity {
    FOO {
      public void perform() { /* FOO */ }
    BAR {
      public void perform() { /* BAR */ }

it's better to write:
  interface Activity {
      void perform();
  enum Activities implements Activity {
    FOO(() -> { /* FOO */ }),
    BAR(() -> { /* BAR */ });

    private final Runnable runnable;

    private Activities(Runnable runnable) {
      this.runnable = runnable;

    public void perform() {;

Here, you have only one class at compile time, the lambdas are created at runtime and the way the hierarchy is implemented is hidden from the public API.
I think the GoF name this design pattern as the external decorator or something like this and it's 'use delegation instead of inheritance' to its full glory.

Now, If this proposal is accepted, at least, instead of changing the spec to introduce sharp types for all kind of enums, adding sharp type only for generics enums,
it will break no code because generics enum currently do not compile.


----- Mail original -----
> De: "mark reinhold" <mark.reinhold at>
> À: "maurizio cimadamore" <maurizio.cimadamore at>
> Cc: platform-jep-discuss at
> Envoyé: Mercredi 7 Décembre 2016 00:49:01
> Objet: JEP 301: Enhanced Enums

> New JEP Candidate:
> - Mark

More information about the platform-jep-discuss mailing list