我正在开发一个不可变类。下面是我的不可变类,请告诉我这是完全不可变的,或者如果我失去了一些东西或它的不可变性可以通过无论如何细分,然后请大家指教..关于不可变类完整功能
public final class ImmutableReminder{
private final Date remindingDate;
public ImmutableReminder (Date remindingDate) {
if(remindingDate.getTime() < System.currentTimeMillis()){
throw new IllegalArgumentException("Can not set reminder” +
“ for past time: " + remindingDate);
}
this.remindingDate = new Date(remindingDate.getTime());
}
public Date getRemindingDate() {
return (Date) remindingDate.clone();
}
}
从我的角度来看,没关系:)但是不要忘记检查null – Taras 2013-03-04 14:54:18
构造函数已经检查'null' ...暗含地:-) – 2013-03-04 15:26:41