So, I read somewhere that there are 3 requirements for a class to be immutable in Java.
- All data fields must be private.
- There can't be any mutator methods for data fields.
- No accessor methods can return a reference to a data field that is mutable.
But I don't agree with #2 because even if a class has mutator methods, it can be immutable as long as those mutator methods are private. Am I right or wrong? Can you explain in detail?