Field may be 'final'
Reports fields that can be safely made final. All final fields have a value and this value does not change, which can make the code easier to reason about.
To avoid too expensive analysis, this inspection only reports if the field has a private modifier or it is defined in a local or anonymous class. A field can be final if:
It is
staticand initialized once in its declaration or in onestaticinitializer.It is non-
staticand initialized once in its declaration, in one instance initializer or in every constructor
And it is not modified anywhere else.
Example:
After the quick-fix is applied:
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.
FieldMayBeFinal- 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.
Use the "Annotations" button to modify the list of annotations that assume implicit field write.
Inspection options
Here you can find the description of settings available for the Field may be 'final' inspection, and the reference of their default values.
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: |