This is not allowed by the Java Language specification.
11/14. The Switch Statement states that
The type of the expression must be char, byte, short, int, Character, Byte, Short, Integer, String or enum type ( Β§8.9 ), or a compile-time error occurs.
Here, expression is the value that you include ( switch(expression) ). In your case, the type of expression is Units , which is an interface, not an enum .
Next to this
Each case label has a case constant, which is either a constant expression or the name of an enum constant.
The enum constants do not match the type of enumeration, so you cannot mix different variables of the enumeration type in the switch.
A possible solution for you would be to implement it as follows:
interface Unit { void doSomething(); } enum A implements Unit { A_ONE, A_TWO, A_THREE { void doSomething() {
Thus, each enumeration that Unit implements can and should contain processing logic encapsulated inside it, and if you have any special constant constants, they can implement special logic themselves. Naturally, sometimes each enumeration constant can have a certain implementation, and at the level of the enumeration class there will not be a single generic one.