我不明白为什么这个方法会抛出异常:
public void add(Object obj){
gameObjects.add(obj); //here the exception happens
}
...虽然这个没有:
public void add(Object obj){
gameObjects.add(obj); // no exception actually happens here
gameObjects.remove(obj);
}
考虑到这是运行时异常,为什么会发生这种情况?
例外:
Exception in thread "Thread-0" java.util.ConcurrentModificationException
at java.util.ArrayList$Itr.checkForComodification(Unknown Source)
at java.util.ArrayList$Itr.next(Unknown Source)
at threads.Main.tick(Main.java:181)
at threads.Main.run(Main.java:104)
该方法为对象内的刻度方法调用。
gameObjects
不为空:
List<Object> gameObjects = new ArrayList<Object>(128);