ArrayList Confusion - Changing an object instance's variables after extracting an object with .get()
in
Programming Questions
•
8 months ago
EDIT: Made the title and final question a little clearer.
I'm trying to make a simple top down shooter game, and was considering using an ArrayList to hold Enemy objects, which have an enemyMovement() method. If I were to extract them from the ArrayList in the same manor as the Ball example...:
(Not actual part of my code just yet, just renamed variables to show what my plan is)
Enemy enemy = (Enemy) enemyList.get(i)
enemy.enemyMovement(); // x = x+1; y = y+1; for example
enemy.drawEnemy();
if (enemy.health == 0)
{
enemy.remove(i);
}
...are changes to the Enemy objects, done by enemy.enemyMovement(), automatically updated in the original object in the ArrayList or must I do that myself with an extra command?
1