请注意此代码:
public Period(Date start, Date end) {
this.start = new Date(start.getTime());
this.end = new Date(end.getTime());
if (this.start.compareTo(this.end) > 0)
throw new IllegalArgumentException(start +" after "+ end);
}
compareTo()
如果在防御性地将可变参数复制到构造函数之前完成对参数有效性的检查(即调用),我不明白这有什么关系?