문제

For the following code

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

I get the PMD warning: "Use equals() to compare object references". But if I follow this proposal, I'll get a NPE. Is it a bug of PMD rule or my programming style is simply bad?

도움이 되었습니까?

해결책

Just change it a little bit:

boolean changed = null == oldValue ? newValue != null : !oldValue.equals(newValue);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top