Why not extending from Enum>

前端 未结 5 636
无人及你
无人及你 2021-01-19 06:36

I stumbled over the following problem that i can\'t extend and implement from this class which is defined in Java 1.5 (java.lang package)

public abstract cla         


        
5条回答
  •  情话喂你
    2021-01-19 06:52

    Enum gets special treatment by the compiler and classes like EnumSet make assumptions based on this treatment. The behavior of Enum methods like ordinal() and name() is strictly defined and implementing them yourself to replicate this behavior makes no sense. Also the syntax to declare enum values is only valid in an enum and wont compile in a class.

    It is important to remember that you should never use ordinal() yourself, so defining it to suit your problem makes no sense.

提交回复
热议问题