【发布时间】:2014-07-01 20:57:58
【问题描述】:
这是我的代码:
private void showMessageForInvalid(File aFile) {
if (!aFile.exists()) {
// show not exists message
} else if (!aFile.isDirectory()) {
// show not directory message
}
}
对于第一个 if 块,我收到 PMD 警告“避免 x!= y else”。我认为,这个警告是正确的,以防万一
if (!aFile.exists()) {
// do something
} else {
// do else
}
但在我的情况下,else if 声明并非如此。
这是 PMD 错误还是此警告正确(在这种情况下我应该如何编写代码)?
【问题讨论】:
-
这可能是因为 pmd 认为积极的结果应该在
if else块中排在第一位。