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

org.sonar.l10n.java.rules.squid.StringEqualityComparisonCheck.html Maven / Gradle / Ivy

There is a newer version: 8.6.0.37351
Show newest version

Strings, just like any other Object, should be compared using the equals() method.

Using == and != compares references rather than values, and usually does not work.

Noncompliant Code Example

if (variable == "foo") { /* ... */ }
if (variable != "foo") { /* ... */ }

Compliant Solution

if ("foo".equals(variable)) { /* ... */ }    // Compliant
if (!"foo".equals(variable)) { /* ... */ }   // Compliant

See

This rule is deprecated, use {rule:squid:S1698} instead.





© 2015 - 2025 Weber Informatics LLC | Privacy Policy