Why would one declare an immutable class final in Java?
I read that to make a class immutable in Java, we should do the following, Do not provide any setters Mark all fields as private Make the class final Why is step 3 required? Why should I mark the class final ? templatetypedef If you don't mark the class final , it might be possible for me to suddenly make your seemingly immutable class actually mutable. For example, consider this code: public class Immutable { private final int value; public Immutable(int value) { this.value = value; } public int getValue() { return value; } } Now, suppose I do the following: public class Mutable extends