It's not a secret anymore!*
The moose likes Beginning Java and the fly likes is there any way to  extend an enum from other enum Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "is there any way to  extend an enum from other enum" Watch "is there any way to  extend an enum from other enum" New topic
Author

is there any way to extend an enum from other enum

srini carry
Ranch Hand

Joined: Nov 30, 2007
Posts: 83
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

Joined: Mar 09, 2009
Posts: 600
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

Joined: Nov 30, 2007
Posts: 83
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

Joined: Mar 09, 2009
Posts: 600
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

Joined: Oct 27, 2005
Posts: 19651
    
  18

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
 
subject: is there any way to extend an enum from other enum
 
Similar Threads
Restricting Sub-class declaration
inner class
Enum-doubt
Question about Enum Class Qualified
enum cannot be final or abstract