
org.sonar.l10n.java.rules.squid.StringEqualityComparisonCheck.html Maven / Gradle / Ivy
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.
The following code:
Noncompliant Code Example
if (variable == "foo") { /* ... */ }
if (variable != "foo") { /* ... */ }
Compliant Solution
See
- MITRE, CWE-597 - Use of Wrong Operator in String Comparison
© 2015 - 2025 Weber Informatics LLC | Privacy Policy