public final class Multi {
private final String name;
private final int number;
private final ArrayList<String> otherNames;
Multi(String name, int number) {
this.name = name;
this.number = number;
this.otherNames = new ArrayList<String>();
}
public void addOtherNames(String name) {
this.otherNames.add(name);
}
// All getter methods should be a copy of the class fields
public ArrayList<String> getOtherNames() {
return new ArrayList<String>(otherNames);
}
}
I am having some trouble understanding immutability when it involves data structures such as ArrayList ect.
When I have a method such as addOtherNames which will add contents to the list after object creation.
Thanks