【发布时间】:2015-05-24 10:59:37
【问题描述】:
public static void mouseAction(String action, int x, int y) {
for (Iterator<ArrayList<GameObject>> j = obj.iterator(); j.hasNext();) {
ArrayList<GameObject> g = j.next();
for (Iterator<GameObject> i = g.iterator(); i.hasNext();) {
if (i.next() instanceof MouseInteractable) {
switch (action) {
case "click":
((MouseInteractable) i.next()).onClick(x, y);
break;
case "move":
((MouseInteractable) i.next()).onMove(x, y);
break;
}
}
}
}
}
由于某种原因给了我一个没有这样的元素例外。 当我用普通的 for 循环替换迭代器时,它工作得很好。但在某些情况下,我需要在迭代对象时(通过鼠标单击)编辑对象,因此我需要一个迭代器,但它不起作用......
【问题讨论】:
标签: java