• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

enum extending abstract class

 
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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,


 
Sheriff
Posts: 9708
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

 
Sheriff
Posts: 22791
131
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can't you simply do that with enums?
 
Paper jam tastes about as you would expect. Try some on this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic