Why can't a class extend an enum?

后端 未结 5 1907
死守一世寂寞
死守一世寂寞 2021-01-17 10:18

I am wondering why in the Java language a class cannot extend an enum.

I\'m not talking about an enum extending an enum<

5条回答
  •  一个人的身影
    2021-01-17 10:51

    May I also add that we can emulate Extensible enums using interfaces.

    From Joshua Bloch's brilliant book

    http://books.google.com/books?id=ka2VUBqHiWkC&pg=PA165&lpg=PA165&dq=mulate+extensible+enums+with+interfaces&source=bl&ots=yYKhIho1R0&sig=vd6xgrOcKr4Xhb6JDAdkxLO278A&hl=en&sa=X&ei=XyBgUqLVD8-v4APE6YGABg&ved=0CDAQ6AEwAQ#v=onepage&q=mulate%20extensible%20enums%20with%20interfaces&f=false

    or

    http://jtechies.blogspot.com/2012/07/item-34-emulate-extensible-enums-with.html

提交回复
热议问题