“Using non reentrant iterator method: Array.iterator()”错误消息是什么意思?

What does “Using non reentrant iterator method: Array.iterator()” error message mean?

这是我在 libGDX 中的第一个项目,我正在尝试循环 com.badlogic.gdx.utils.Array:

//properties
...
private Array<Item> items;
...
//constructor
...
    items = new Array<Item>();
...
//render method
...
    for (Item item : items) {
        item.update(deltaTime);
    }
...

Android 工作室正在突出显示 items 悬停消息:

Using non reentrant iterator method: Array.iterator()

Iterator methods on LibGDX collections return the same iterator instance each time the method is called. For nested or multithreaded iteration create a new iterator using the appropriate constructor

我不确定如何解决这个问题,或者这是否只是一个通知类型的错误,以及它是否影响了长 运行.

上的任何内容

知道这是什么以及如何解决吗?

就像它说的那样in the documentation:

Note that the same iterator instance is returned each time this method is called.

因此,如果您从两个不同的线程调用它,则在一个线程中调用 next 会推进另一个线程中的迭代器。

(或者,在同一个线程中调用它两次,并且在一个实例上调用 next 也会推进另一个实例。这与线程本身无关)。

Use the Array.ArrayIterator constructor for nested or multithreaded iteration.

使用 new Array.ArrayIterator<>(items) 而不仅仅是 items