我有一个包含枚举的类和包含该对象列表的类
public enum State {
ACTIVE,NOT_ACTIVE;
}
public class SomeObject {
State state;
public SomeObject(State state) {
this.state = state;
}
}
public class SomeObjects{
State state;
ArrayList<SomeObject> objects = new ArrayList<Main.SomeObject>();
public SomeObjects(int count) {
state = State.ACTIVE;
for (int i = 0; i < count; i++) {
objects.add(new SomeObject(state));
}
}
public void changeState(State state) {
this.state = state;
}
}
现在如果我使用changeState(State.NOT_ACTIVE)
它会改变SomeObjects和列表中所有对象的状态还是只在 SomeObjects 中?
如果仅在SomeObjects中,我应该怎么做才能更改列表中所有对象的状态changeState()
?
在这种情况下,创建包含该枚举的类是唯一的方法吗?
更新:谢谢,但在我的情况下,我需要更改所有对象的状态
this.state = state;