unj2 unj2 - 1 year ago 132
Java Question

What is the right position of literals in String Comparison?

I have

if (localName.equals("TaxName")) {

but PMD says

Position literals first in String comparisons

Answer Source

"TaxName".equals(localName) is better as if localName is null you won't get a null pointer exception.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download