if(x!=y) vs if(x==y)
我已经在Eclipse中针对我的代码运行了PMD插件,并且我收到了类似于如下所示的代码的高优先级警告:
if(singleRequest !=null){
// do my work
}else{
// do my other work
}
PMD 说`Avoid if (x != y) ..; else ..
;
错误的描述如下所示:
In an "if" expression with an "else" clause, avoid negation in
the test. For example, rephrase:
if (x != y) diff(); else same();
as:
if (x == y) same(); else diff();
Most "if (x != y)" cases without an "else" are often return
但我仍然无法理解对我的代码的影响。如果有人能用一个例子指导我,我将不胜感激。