• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

enum extending abstract class

 
Udayan Kumar
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All

The current jdk feature of Enums does not allow the enum to inherit an abstract class. I am aware about having an abstract method inside the enum and the enum instances providing implementation for the abstract enum method. But I am trying to find a solution using Enum/abstract class workaround to the below mentioned scenario.
The reason I ask this question is I don't want to break our existing design which has an abstract class and only one abstract method and the rest of the methods are implemented methods. This abstract method is to be overriden by the derived classes. So they also inherit the complete methods defined by the parent class.
I don't want to spawn multiple derived classes but keep the implementation concise in an Enum so all the instances in enum will override the abstract method from the aforementioned abstract class.
How can I achieve this?


Regards,


 
Ankit Garg
Sheriff
Posts: 9521
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Udayan an enum is just like a class. Every enum extends the Enum class so they cannot extend any other class. You can achieve what you want by declaring static final fields in your class which has one abstract method or create class and use static final implementations using anonymous inner classes in it like this

 
Rob Spoor
Sheriff
Pie
Posts: 20545
56
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can't you simply do that with enums?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic