resources.report.rules.pmd.UseEqualsToCompareStrings.html Maven / Gradle / Ivy
UseEqualsToCompareStrings
UseEqualsToCompareStrings
Using ‘==’ or ‘!=’ to compare strings only works if intern version is used on both sides. Use the equals() method instead.
//EqualityExpression/PrimaryExpression
[(PrimaryPrefix/Literal
[starts-with(@Image, '"')]
[ends-with(@Image, '"')]
and count(PrimarySuffix) = 0)]
Example(s):
public boolean test(String s) {
if (s == "one") return true; // unreliable
if ("two".equals(s)) return true; // better
return false;
}