Get information about array containing object - Java

166 Views Asked by At

I have a bunch of objects in an array in Greenfoot, when act(loop that keeps game going) runs I need to get some information about the array from within the object that belongs to it. What ways are there for getting information about the array from within the objects it contain?

1

There are 1 best solutions below

2
On

Store a reference in the object to the list. For example:

class MyObject {
   List owner;
   // ...
   public void setOwner(List owner) { this.owner = owner; }
}

In this way, you can access to the owner list from any method in MyObject. When you add the object to the list, don't forget to call the "setOwner" method.