【发布时间】:2021-01-29 05:01:30
【问题描述】:
我正在尝试根据 2 个条件验证参数。 必须是字符串,不区分大小写。如果参数不等于“title”或“author”,它应该抛出一个错误。代码的第一部分似乎有效,但第二部分说它总是正确的,我每次都会出错。这是部分代码。
if(!"title".equalsIgnoreCase(property))
{
throw new IllegalNovelPropertyException("Bad Property");
}
if(!"author".equalsIgnoreCase(property))
{
throw new IllegalNovelPropertyException("Bad Property");
}
【问题讨论】:
-
if (! "title".equalsIgnoreCase(property) && ! "author".equalsIgnoreCase(property)) { ...另外,您应该声明,该属性应该匹配作者或标题... -
完美,成功了。谢谢。
标签: java illegalargumentexception throws