Are Immutable objects immune to improper publication?
问题 It is an example from JCiP. public class Unsafe { // Unsafe publication public Holder holder; public void initialize() { holder = new Holder(42); } } public class Holder { private int n; public Holder(int n) { this.n = n; } public void assertSanity() { if (n != n) { throw new AssertionError("This statement is false."); } } } On page 34: [15] The problem here is not the Holder class itself, but that the Holder is not properly published. However, Holder can be made immune to improper