This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

is there any way to extend an enum from other enum

 
srini carry
Ranch Hand
Posts: 83
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I using enums with some abstract methods etc. I created new enum and eanted to extend this with the prior and compiler tells it as error. Is there any workaround for entending enum to other enum ?
 
John de Michele
Rancher
Posts: 600
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Miro,

I don't think an enum class can extend another class. Enums can implement interfaces, though, so you may want to move those abstract methods into an interface, and just have your enum class implement them.

John.
 
srini carry
Ranch Hand
Posts: 83
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
John de Michele wrote:Miro,

I don't think an enum class can extend another class. Enums can implement interfaces, though, so you may want to move those abstract methods into an interface, and just have your enum class implement them.

John.


but this way I have to implement methods in both the enum classes which will be of no use
 
John de Michele
Rancher
Posts: 600
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
but this way I have to implement methods in both the enum classes which will be of no use


What are you trying to do?

John.
 
Rob Spoor
Sheriff
Pie
Posts: 20372
44
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The only subclasses an enum can have are anonymous subclasses that are defined in the enum itself. For example:
These are also the reason there is a getDeclaringClass(). ONE.getClass() would not return MyEnum.class, whereas ONE.getDeclaringClass() would.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic