All Downloads are FREE. Search and download functionalities are using the official Maven repository.

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;
}





© 2015 - 2024 Weber Informatics LLC | Privacy Policy