Enums in Java is final , which means you cannot extend and enumerate (you cannot add more values to an existing enumeration). In your case, ABC and DEF are completely different objects with simple, identical enumeration element names. This implies, for example, that ABC.A != DEF.A
There are many ways to deal with this, but none of them are perfect or simple. You must convince what is necessary in your particular case.
The first way to handle this is to create a common interface that your enums can extend:
interface MyInterface{ } enum ABC implements MyInterface{ A,B,C; } enum DEF implements MyInterface{ A,B,C,X,Y,Z,D; }
This way you can use both ABC and DEF in doSomething() :
Class Test{ public void doSomething(MyInterface abc) {
Another approach is to add generics to your class. Thus, you can create specific implementations that will support the specified enumeration:
class GenericTest<E extends Enum<E>>{ public void doSomething(E enum){ } } class TestWhichAcceptsABC extends GenericTest<ABC>{} class TestWhichAcceptsDEF extends GenericTest<DEF>{}
The third way is to create several methods, one for each enumeration that needs to be processed
Class Test{ public void doSomething(ABC abc) {
See this thread for more ideas on how to solve enum inheritance.