Dee*_*onZ 0 java enums enumeration
我想实现一个返回一个或一个允许的动作列表定义为枚举的方法.
例如,我的方法应该是这样的:
public enum getAllowedActions() {
return // (( 'something like' Actions.ACTION1 & Actions.ACTION2 ));
}
Run Code Online (Sandbox Code Playgroud)
然后在另一个位置读取结果,如:
if (getAllowedActions() == Actions.ACTION1) {
// do something...
}
Run Code Online (Sandbox Code Playgroud)
有:
public class enum {
ACTION1, ACTION2;
}
Run Code Online (Sandbox Code Playgroud)
谢谢.斯特凡诺.
听起来像你只是寻找EnumSet:
public EnumSet<Action> getAllowedActions() {
return EnumSet.of(Action.ACTION1, Action.ACTION2);
}
...
if (getAllowedAction().contains(Action.ACTION1)) {
...
}
Run Code Online (Sandbox Code Playgroud)