unj2 unj2 - 1 year ago 108
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.