This question is about good programming practices and avoiding potential holes.
I read Joshua Bloch\'s Effective Java and here is what I wonder:
Why should I conside
While the enclosing class may be immutable, the references returned by its getter methods might be mutable, allowing the caller to modify the immutable's transitive state. Example:
public class MyImmutable
{
private final StringBuilder foo = new StringBuilder("bar");
public StringBuilder getFoo()
{
return foo; // BAD!
}
}
You should use private for encapsulation (prevent classes from depending on your class' implementation details). You should use final to make sure you don't modify the field by mistake if it isn't meant to be modified (and yes, it might help performance).