Creating an immutable object without final fields?
问题 Can we create an immutable object without having all fields final? If possible a couple of examples would be helpful. 回答1: Declare all fields private and only define getters: public final class Private{ private int a; private int b; public int getA(){return this.a;} public int getB(){return this.b;} } citing @Jon Skeet's comment, final class modifier is useful for: While an instance of just Private is immutable, an instance of a subclass may well be mutable. So code receiving a reference of