完全可以创建自己的只读类,下面是个简单的例子: //: Immutable1.java // Objects that cannot be modified // are immune to aliasing. public class Immutable1 { private int data; public Immutable1(int initVal) { data = initVal; } public int read() { return data; } public boole
问题描述 java可变类和不可变类区别中,对于不可变类克隆的问题 import java.util.Date; public final class BrokenPerson { private String firstName; private String lastName; private Date dob; public BrokenPerson( String firstName, public BetterPerson( String firstName, String lastNa