News for hackers. Stuff that matters.
Re:Immutable annotations for Java by molyss on Sunday July 12, 2015 @01:02PM (#9874071)
if a class definition contains a Map that's declared final, nothing prevents anyone from mutating the map itself, if there's a public getter to it.

In order for a class to be immutable, all its fields need to be be immutable and final. Immutability got to be recursive.

Also, in Java, the class should be final, otherwise nothing prevents anyone from extending it and pass a mutable data structure instead of the immutable one you'd expect

Edit : added the "in java", as we could imagine another language where immutable doesn't require objects to be final.

There are no comments on this comment yet.