This is my first project in libGDX
and I am trying to loop a 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 studio is highlighting items
with message on hover:
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
I am not sure how to solve this, or if this is just a notice type of error, and if it is affecting anything on the long run.
Any ideas what this is and how to solve it?
Like it says in the documentation:
Note that the same iterator instance is returned each time this method is called.
So, if you called this from two different threads, calling next in one thread would advance the iterator in the other thread.
(Or, call it twice in the same thread, and calling next on one instance would advance the other instance too. It's not about threads, per se).
Use the Array.ArrayIterator constructor for nested or multithreaded iteration.
Use new Array.ArrayIterator<>(items)
instead of just items
.