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)
Locating this inspection
- By ID
Can be used to locate inspection in e.g. Qodana configuration files, where you can quickly enable or disable it, or adjust its settings.
UnusedAssignment- Via Settings dialog
Path to the inspection settings via IntelliJ Platform IDE Settings dialog, when you need to adjust inspection settings directly from your IDE.
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 ID: UnusedAssignment
Inspection options
Here you can find the description of settings available for the Unused assignment inspection, and the reference of their default values.
- Report redundant initializers
Option ID:
REPORT_REDUNDANT_INITIALIZERDefault value:
Selected- Report prefix expressions that can be replaced with a binary expression
Option ID:
REPORT_PREFIX_EXPRESSIONSDefault value:
Not selected- Report postfix expressions where the changed value is not used
Option ID:
REPORT_POSTFIX_EXPRESSIONSDefault value:
Selected- Report pattern variables whose values are never used
Option ID:
REPORT_PATTERN_VARIABLEDefault value:
Selected- Report iteration parameters whose values are never used
Option ID:
REPORT_FOR_EACH_PARAMETERDefault value:
Selected
Suppressing Inspection
You can suppress this inspection by placing the following comment marker before the code fragment where you no longer want messages from this inspection to appear:
More detailed instructions as well as other ways and options that you have can be found in the product documentation:
Inspection Details | |
|---|---|
By default bundled with: |