As you know, the java enum class:
- implicitly extends java.lang.Enum;
- cannot extend to other enum classes.
I have several enum classes as shown below:
enum ResourceState {
RUNNING, STOPPING,STARTTING;
void aMethod() {
}
}
enum ServiceState {
RUNNING, STOPPING,STARTTING,ERROR;
void aMethod() {
}
}
The method is aMethod()in listing ResourceStateand ServiceStateexactly the same.
OOP, if ResourceStateand ServiceStateare not enumerated, they need to abstract one and the same method of super-abstract class, for example:
abstract class AbstractState{
void aMethod() {
}
}
but ResourceState cannot extend from AbstractState, do you have any ideas for work?
source
share