mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-16 14:23:28 +07:00
30 lines
1.5 KiB
HTML
30 lines
1.5 KiB
HTML
<html>
|
|
<body>
|
|
Reports calls to <code>toString()</code> that are used in the following cases:
|
|
<ul>
|
|
<li>In string concatenations</li>
|
|
<li>In the <code>java.lang.StringBuilder#append()</code> or <code>java.lang.StringBuffer#append()</code> methods</li>
|
|
<li>In the methods of <code>java.io.PrintWriter</code> or <code>java.io.PrintStream</code></li>
|
|
<li>in the methods <code>org.slf4j.Logger</code></li>
|
|
</ul>
|
|
<p>In these cases, conversion to string will be handled by the underlying library methods,
|
|
and the explicit call to <code>toString()</code> is not needed.
|
|
Removing redundant <code>toString()</code> calls can occasionally even improve performance and reduce object allocations.</p>
|
|
<p>Example:</p>
|
|
<pre><code>
|
|
System.out.println(this.toString())
|
|
</code></pre>
|
|
<p>After the quick-fix is applied:</p>
|
|
<pre><code>
|
|
System.out.println(this)
|
|
</code></pre>
|
|
<!-- tooltip end -->
|
|
<p>
|
|
Note that without the <code>toString()</code> call, the code semantics might be different: if the expression is null,
|
|
then the <code>null</code> string will be used instead of throwing a <code>NullPointerException</code>.</p>
|
|
<p>Use the <b>Report only when qualifier is known to be not-null</b> option to avoid warnings for the values that could potentially be null.
|
|
Removing the explicit <code>toString()</code> in these cases will change the runtime semantics
|
|
from throwing a <code>NullPointException</code> to silently accepting the value when it is <code>null</code>.
|
|
</p>
|
|
</body>
|
|
</html> |