当我创建一个EnumSet并通过函数发送它时,我发现自己无法达到EnumSet中设置的Enum值.我只能将它与原始集进行比较,并检查它是否存在.我不希望这样,因为这会迫使我浪费一些代码,迫使我每次都要接触原始Enum课程.
for(Action a : Action.values())
{
if(stateCommands.contains(a))
{
System.out.println(a.getCommand() + a.getDescription());
}
}
Run Code Online (Sandbox Code Playgroud)
我想迭代stateCommands并能够看到它的内容.
我该怎么办呢?
Lou*_*man 11
for(StateCommand command : stateCommands) {
// do whatever
}
Run Code Online (Sandbox Code Playgroud)
就像其他任何一样Set
.或者,如果你需要做一些更复杂的事情,只需使用stateCommands.iterator()
.