I have an ArrayList of objects, which are used in subclasses of a helperclass. I’m sending the data needed to the subclass, eg new subclass(ArrayListObject), and these subclasses are handled in a map structure in the helperclass. Since a single ArrayListObject is stored in the helperclass, I assumed it would be linked in the subclasses, which need this object for calculations. However, when changed the ArrayListObject is not changed in the subclasses, from what I’m seeing in the debugger.
Is there a way to make this a pointer to another class variable? Or is the most appropriate way to handle this to make the subclass receive a reference to the helperclass in the constructor, to call a helperclass.getArrayObject method?
What you are trying to accomplish, a pointer, is not available in Java. To work around this, you should make the
ArrayListObjecta protected field of the helperclass. There are two ways to go from here:super.mArrayListwhenever you need the value.getArrayListObject()that returns the value of the object.