public class Thing implements Parcelable{ public List<String> mFotos; public Thing(ArrayList<String> fotos){ if (fotos == null) mFotos = new FotoList(); else mFotos = new FotoList(fotos); } 

How to make access to the method of the mFotos object was, and the reference to the mFotos object created in the constructor was mFotos . Well, that is, you cannot assign another reference to the mFotos variable, and you can contact the method:

 thing.mFotos.add("Строка"); 
  • one
    declare mFotos to be final. - pavel
  • Damn, just because. After all, this is a common variable. Thank you very much. - Frozik6k
  • You can also duplicate all mFotos methods in the class thing in this way: public void add(String s) {mFotos.add(s);} - Vladyslav Matviienko
  • I thought about this, but it looks somehow cumbersome and wrong. - Frozik6k

1 answer 1

The final keyword ensures that the variable is safe from changes. If no value is initially assigned, then it is possible to assign the value to a variable, but only once.

 public class Thing implements Parcelable{ public final List<String> mFotos; public Thing(ArrayList<String> fotos){ if (fotos == null) mFotos = new FotoList(); else mFotos = new FotoList(fotos); } 

After the reference to the object is assigned to the mFotos variable in the constructor, you cannot write another reference to the variable.