extending enum in java

Wed Sep 16, 2009 1:21 am

Extending enum in java. Can we extend (inherit) an enum type.
extending enums in java is not allowed. As example suppose you have two enums A and B .Y
You can't do the following :

Code:

enum B
{
}
enum A extends enum B
{
   // Define you enum here .
} 



And in the same time you can't use implements keyword , because B is not an interface ,But if your system need both to be same type , for example if you want to define one function signature to take both enums as parameters you can do it by defining an enum and implementing it in both enums .

Code:

interface enuminterface
enum B implements enuminterface
{
}
enum A  implements enuminterface

{
   // Define you enum here .
} 


and your signature will be something like this :
Code:
 return type myfunction (enuminterface Enumparam)  ;  




  Related Posts  to : extending enum in java
 Java extending org.apache.log4j.Logger     -  
 Java enum example     -  
 Define enum in java     -  
 Extending Quartz Scheduler Job Interface     -  
 Enum Declaration     -  
 how to use enum in jaxb unmarshalling     -  
 Define Enum inside a class     -  
 Passing Enum as Type Parameter to method     -  
 2d game in java-Monster-Java 2D Game Graphics and Animation     -  
 Java course     -  

Topic Tags

Java OOP