Consider this enum which I want to use as a state machine:
public enum PositionFSM {
State1 {
@Override
PositionFSM processFoo() {
return State2;
}
},
State2 {
@Override
PositionFSM processFoo() {
return State1;
}
};
abstract PositionFSM processFoo();
abstract PositionFSM processBar();
PositionFSM processBar() {
return this;
}
}
The goal is to avoid that all states must implement all events for which they do nothing but return the current state.
In this example a call for processBar
should be ignored by State1
and State2
.
I'm referring to this answer, but the enum given will not compile(Java 1.8). Is there a way for doing it the way I want?