Files
openide/java/java-impl/resources/inspectionDescriptions/UnusedAssignment.html
Leonid Shalupov 40795fe787 IJI-2422: community/java: move resources under resources root
GitOrigin-RevId: 8b2b63fc6db476ca0c2cfe5cadd84db6c4236d0f
2025-02-05 04:43:28 +00:00

65 lines
1.9 KiB
HTML

<html>
<body>
Reports assignment values that are not used after assignment.
If the assignment value is unused, it's better to remove the assignment to shorten the code and avoid redundant allocations.
<p>The following cases are reported:</p>
<ul>
<li>variables that are never read after assignment</li>
<li>variables that are always overwritten with a new value before being read</li>
<li>variable initializers that are redundant (for one of the two reasons above)</li>
</ul>
<!-- tooltip end -->
<p>Configure the inspection:</p>
<p>
Use the <b>Report redundant initializers</b> option to report redundant initializers:
</p>
<pre><code>
int getI() {
int i = 0; // redundant initialization
i = 2;
return i;
}
</code></pre>
<p>
Use the <b>Report prefix expressions that can be replaced with binary expressions</b> option to report cases
where an <code>++i</code> expression may be replaced with <code>i + 1</code>:
</p>
<pre><code>
int preInc(int value) {
int res = value;
return ++res;
}
</code></pre>
<p>
Use the <b>Report postfix expressions where the changed value is not used</b> option to report <code>i++</code> cases
where the value of <code>i</code> is not used later:
</p>
<pre><code>
int postInc(int value) {
int res = value;
return res++;
}
</code></pre>
<p>
Use the <b>Report pattern variables whose values are never used</b> option to report cases where the value of a pattern variable
is overwritten before it is read:
</p>
<pre><code>
if (object instanceof String s) {
s = "hello";
System.out.println(s);
}
</code></pre>
<p>
Use the <b>Report iteration parameters whose values are never used</b> option to report cases where the value of an iteration parameter
of an enhanced <code>for</code> statements is overwritten before it is read:
</p>
<pre><code>
for (String arg : args) {
arg = "test";
System.out.println(arg);
}
</code></pre>
</body>
</html>