Vra

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?

Was dit nuttig?

Oplossing

Just change it a little bit:

boolean changed = null == oldValue ? newValue != null : !oldValue.equals(newValue);
Gelisensieer onder: CC-BY-SA met toeskrywing
Nie verbonde aan StackOverflow
scroll top