我想避免创建一个开关盒,而是使用一个,enum
但是在编写以下代码时,我得到一个编译错误说unexpected token public
:
public enum Status {
INACTIVE {
public void doSomething() {
//do something
}
},
ACTIVE {
public void doSomething() {
//do something else
}
},
UNKNOWN {
public void doSomething() {
//do something totally different
}
};
public abstract void doSomething()
}
基本上我想要实现的是与此类似的东西:
public enum Status {
ACTIVE,
INACTIVE,
UNKNOWN;
}
switch (getState()) {
case INACTIVE:
//do something
break;
case ACTIVE:
//do something else
break;
case UNKNOWN:
//do something totally different
break;
}
Gosu允许这样做吗?我应该如何实现这种行为?