This question brings up the issues surrounding code like the following (copied from that question):
public MyClass {
public void initialize(Collection<String> data) {
this.data = data; // <-- Bad!
}
private Collection<String> data;
}
Storing a reference opens up doors to bugs through accidentally injecting data into the private field data. The accepted answer by Aaron Digulla suggests a policy of freezing sets with Collection.setUnmodifiable(set); before passing it around, but he mentions that the tradeoff is a performance hit, as anybody who wants to modify the collection needs to copy it, change it, and then save it back.
Are there any best practices when dealing with this in extremely resource-limited Android environments?
In my opinion, just keep the reference. One android app doesn’t contain too many codes, and you or your dev team controls all the source code. So the simplest solution works for most situations.