Win a copy of Functional Reactive Programming this week in the Other Languages 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
  • 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
  • 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
  • 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
  • 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: 20667
65
Chrome Eclipse IDE Java Windows
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic