Why not extending from Enum>

前端 未结 5 690
无人及你
无人及你 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 07:14

    The Enum class is special in Java, as it is used to implement the Enum language feature. Thus it is not just a class like any other class in Java, but more special (like String, for which the + operator is overloaded, or like the boxed classes). For these features to work, special requirements are needed for enums (like, I guess, consecutive ordinals). Thus the Java Language Specification explicitly forbids manually inheriting from the Enum class.

提交回复
热议问题