源码如下,当参数不是Calendar的实例时返回的是false,但请问这样的比较有意义吗?
我个人觉得参数类型是不是不妥?比如我拿Date类型去做比较,不抱任何错,但其实永远返回的都是false。
public boolean before(Object when) {
return when instanceof Calendar
&& compareTo((Calendar)when) < 0;
}
public boolean after(Object when) {
return when instanceof Calendar
&& compareTo((Calendar)when) > 0;
}
//我认为这样比较合理
public boolean after(Canlendar when) {
return compareTo(when) > 0;
}
Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
认证高级PHP讲师