PMD等于警告错误?

时间:2014-05-15 08:00:57

标签: java pmd

以下代码

boolean changed = null == oldValue? oldValue != newValue : !oldValue.equals(newValue);

我收到PMD警告:"使用equals()来比较对象引用"。但如果我遵循这个提议,我会得到一份NPE。这是PMD规则的错误还是我的编程风格简直不好?

1 个答案:

答案 0 :(得分:5)

稍微改变一下:

boolean changed = null == oldValue ? newValue != null : !oldValue.equals(newValue);