是否有可能讓一個枚舉常量擴展另一個枚舉(來自同一個枚舉)?擴展和枚舉常量
僞代碼:
private enum Mode{
FRIGHTENED, BLINKING extends FRIGHTENED, SCATTER
}
通過這種方式,可以使用枚舉常數在switch
- 塊是這樣的:
switch (some_mode){
case FRIGHTENED:
// This would trigger when the actual "some_mode" is set
// to FRIGHTENED or BLINKING
break;
case BLINKING:
// This would only trigger if the actual "some_mode" is set to BLINKING
}
是否有這將讓我的任何模式要做到這一點,還是我完全不在意?
我可能會是一個更加清楚一點關於在switch
語句來示出的用例:我打算不檢查所有可能的值,但只適用於「父」之一。
if (some_mode == Mode.FRIGHTENED){
// The behavior in FRIGHTENED and BLINKING mode is the same. The only
// difference is the way they are visualized.
}