【发布时间】:2022-01-06 02:02:24
【问题描述】:
我有以下代码:
LocalDate date;
LocalDate minDate;
//constructor...
if(date.isBefore(minDate)){
throw new RuntimeException();
}
与 LocalDateTime 类似:
LocalDateTime date;
LocalDateTime minDate;
//constructor...
if(date.isBefore(minDate)){
throw new RuntimeException();
}
我可以使用一些接口或抽象类,这样我就不必编写两次相同的代码了吗?我找不到这样的接口。 如您所见,我只使用 'isBefore' 和 'isAfter' 方法。
【问题讨论】:
-
请添加更多上下文!您从哪里获得日期和时间?
-
Comparable 怎么样?