mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-16 14:23:28 +07:00
39 lines
1.6 KiB
HTML
39 lines
1.6 KiB
HTML
<html>
|
|
<body>
|
|
Reports redundant calls to <code>String</code> constructors and methods like <code>toString()</code> or <code>substring()</code>
|
|
that can be replaced with a simpler expression.
|
|
<p>For example, calls to these methods can be safely removed in code
|
|
like <code>"string".substring(0)</code>, <code>"string".toString()</code>, or
|
|
<code>new StringBuilder().toString().substring(1,3)</code>.</p>
|
|
<p>Example:</p>
|
|
<pre><code>
|
|
System.out.println(new String("message"));
|
|
</code></pre>
|
|
<p>After the quick-fix is applied:</p>
|
|
<pre><code>
|
|
System.out.println("message");
|
|
</code></pre>
|
|
<p>
|
|
Note that the quick-fix removes the redundant constructor call, and this may affect <code>String</code> referential equality.
|
|
If you need to preserve it, even though it is considered bad practice, suppress the warning or use the inspection setting to ignore
|
|
redundant <code>String</code> constructor calls.
|
|
</p>
|
|
<!-- tooltip end -->
|
|
<p>
|
|
Use the <b>Do not report String constructor calls</b> option below to not report code like the example above.
|
|
This will avoid changing the outcome of String comparisons with <code>==</code> or <code>!=</code> after applying
|
|
the quick-fix in code that uses <code>new String()</code> calls to guarantee a different object identity.
|
|
</p>
|
|
<p>
|
|
Use the <b>Do not report single argument substring() calls</b> option below to not report code like the following.
|
|
</p>
|
|
<pre><code>
|
|
stringBuilder.append(string.substring(5));
|
|
</code></pre>
|
|
<p>which can be replaced with the following.
|
|
<pre><code>
|
|
stringBuilder.append(string, 5, string.length());
|
|
</code></pre>
|
|
<p><small>New in 2018.1</small></p>
|
|
</body>
|
|
</html> |