mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-07 22:09:38 +07:00
27 lines
1.1 KiB
HTML
27 lines
1.1 KiB
HTML
<html>
|
|
<body>
|
|
Reports <code>equals()</code> calls on <code>StringBuilder</code>, <code>StringBuffer</code> and instances of
|
|
<code>java.util.concurrent.atomic</code> package.
|
|
<p>The <code>equals()</code> method is not overridden in these classes, so it may return <code>false</code> even when the contents of the
|
|
two objects are the same.
|
|
If the reference equality is intended, it's better to use <code>==</code> to avoid confusion.</p>
|
|
A quick-fix for <code>StringBuilder</code>, <code>StringBuffer</code>, <code>AtomicBoolean</code>,
|
|
<code>AtomicInteger</code>, <code>AtomicBoolean</code> and <code>AtomicLong</code> is available
|
|
to transform into a comparison of contents.
|
|
The quick-fix may change the semantics when one of the instances is null.
|
|
<p>Example:</p>
|
|
<pre><code>
|
|
public void test(StringBuilder sb1, StringBuilder sb2) {
|
|
boolean result = sb1.equals(sb2); // Suspicious
|
|
}
|
|
</code></pre>
|
|
<p>After the quick-fix is applied:</p>
|
|
<pre><code>
|
|
public void test(StringBuilder sb1, StringBuilder sb2) {
|
|
boolean result = sb1.toString().equals(sb2.toString());
|
|
}
|
|
</code></pre>
|
|
<!-- tooltip end -->
|
|
<p><small>New in 2017.2</small></p>
|
|
</body>
|
|
</html> |