I am confused over this because having a final field b of type B inside an Object A just ensures that the field b can’t be instantiated again but the state of A can be still be changed by manipulating b internally or externally, so how does final serve the purpose immutablity here?
I am confused over this because having a final field b of type B
Share
finalhelps to implement an immutable object. The immutable object must ensure that any objects it owns are themselves immutable or at least not publicly mutable.There is no royal path to immutability in Java (or otherwise, I may add).