Why would an Enum implement an Interface?

前端 未结 16 2749
长发绾君心
长发绾君心 2020-11-28 01:34

I just found out that Java allows enums to implement an interface. What would be a good use case for that?

16条回答
  •  醉话见心
    2020-11-28 02:08

    Enums are like Java Classes, they can have Constructors, Methods, etc. The only thing that you can't do with them is new EnumName(). The instances are predefined in your enum declaration.

提交回复
热议问题