I have the following code:
class Action {
    public void step(Game game) {
        //if some condition met, 
        // then remove self from action stack
        game.actionStack.remove(this);
}
class Game (
    public ArrayList<Action> actionStack;
    public Game() {
        actionStack = new Arraylist<Action>();
        actionStack.add(new Action());
        while (true) {
            for (Action action : this.actionStack) {
                action.step(this);
            }
        }
    }
}
An exception gets thrown when game.actionStack.remove(this); occurs. Is there a way to remove the element safely from inside the Action class like I want?
 
     
     
     
     
    