[patterns] Match against a enum constant

Maurizio Cimadamore maurizio.cimadamore at oracle.com
Mon Oct 2 10:22:07 UTC 2017

I believe in the medium/long run, we have plans to treat enums as a 
special case of constant patterns. But that's not implemented yet.

In switch, you get support for enums since enums constant have always 
been supported in switch. In other words, what you are seeing is, I 
believe, a result of how things have evolved impl-wise, rather than an 
explicit design choice.


On 02/10/17 11:11, Tagir Valeev wrote:
> Hello!
> Currently switch can match against a enum constant, e.g.:
>    static void switches(TimeUnit t) {
>      switch(t) {
>      case SECONDS:System.out.println("Matches");break;
>      }
>    }
> However it seems that this is no case for __matches operator:
>    static void matches(TimeUnit t) {
>      if(t __matches SECONDS) {
>        System.out.println("Matches");
>      }
>    }
> This cannot be compiled (even if I specify qualified
> TimeUnit.SECONDS). Is this intended difference between switch and
> __matches?
> With best regards,
> Tagir Valeev.

More information about the amber-dev mailing list