Files
openide/java/java-impl/resources/inspectionDescriptions/StringEquality.html
2025-02-05 04:43:28 +00:00

25 lines
730 B
HTML

<html>
<body>
Reports code that uses of <b>==</b> or <b>!=</b> to compare strings.
<p>
These operators determine referential equality instead of comparing content.
In most cases, strings should be compared using <code>equals()</code>,
which does a character-by-character comparison when the strings are different objects.</p>
<p><b>Example:</b></p>
<pre><code>
void foo(String s, String t) {
final boolean b = t == s;
}
</code></pre>
<p>If <code>t</code> is known to be non-null, then it's safe to apply the "unsafe" quick-fix and get the result similar to the following:</p>
<pre><code>
void foo(String s, String t) {
final boolean b = t.equals(s);
}
</code></pre>
<!-- tooltip end -->
<p>
</body>
</html>