i read this , and though one of the answers makes sense, I still feel there's something wrong, so I'll go on and give an example.
suppose you have this class:
public class ClassA {
private List<E> mList;
//Constructor assigns some value to mList...
public List<E> getList() {
return mList;
}
}
This class is said to be immutable , and yet, when I do something like this in another class, say ClassB, stuff happens:
public class ClassB {
//variables and constructors....
public void aFunction(ClassA classAObject) {
List<E> anotherList = classAObject.getList();
//play around with the variable anotherList, and though ClassA is immutable, I can change the value of its mList variable.
}
}
Now I know that I could add that 'final', as mentioned in the link i posted above, but seriously, am I missing something regarding this immutable concept? I mean, is there some reason why it really isn't that immutable?