Unused assignment
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.
The following cases are reported:
variables that are never read after assignment
variables that are always overwritten with a new value before being read
variable initializers that are redundant (for one of the two reasons above)
Configure the inspection:
Use the Report redundant initializers option to report redundant initializers:
Use the Report prefix expressions that can be replaced with binary expressions option to report cases where an ++i
expression may be replaced with i + 1
:
Use the Report postfix expressions where the changed value is not used option to report i++
cases where the value of i
is not used later:
Use the Report pattern variables whose values are never used option to report cases where the value of a pattern variable is overwritten before it is read:
Use the Report iteration parameters whose values are never used option to report cases where the value of an iteration parameter of an enhanced for
statements is overwritten before it is read:
Inspection options
Option | Type | Default |
---|---|---|
Report redundant initializers | Checkbox | true |
Report prefix expressions that can be replaced with a binary expression | Checkbox | false |
Report postfix expressions where the changed value is not used | Checkbox | true |
Report pattern variables whose values are never used | Checkbox | true |
Report iteration parameters whose values are never used | Checkbox | true |
Inspection Details | |
---|---|
Available in: | IntelliJ IDEA 2023.3, Qodana for JVM 2023.3 |
Plugin: | Java, 233.SNAPSHOT |