我有一个字符串格式的日期YYYY/MM/DD HH:MM:SS
,我需要使用前置条件 google guava 类进行验证。我checkArgument
在很多其他地方使用方法。如何使用checkArgument
方法进行验证startDate
以确保它仅采用这种格式YYYY/MM/DD HH:MM:SS
,如果不是,则抛出 IllegalArgumentException 和一些消息。
public Builder startDate(String startDate) {
// validate startDate here using checkArgument if it is not valid then throw IllegalArgumentException.
this.sDate = startDate;
return this;
}
我如何在这里使用 checkArgument 方法?