Inspectopedia Help

Declaration can have 'final' modifier

Reports fields, methods, or classes that may have the final modifier added to their declarations.

Final classes can't be extended, final methods can't be overridden, and final fields can't be reassigned.

Example:

public class Person { private String name; Person(String name) { this.name = name; } public String getName() { return name; } public String toString() { return getName(); } }

After the quick-fix is applied:

public final class Person { private final String name; Person(String name) { this.name = name; } public final String getName() { return name; } public final String toString() { return getName(); } }

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.

CanBeFinal
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.

Settings or Preferences | Editor | Inspections | Java | Declaration redundancy

Use the Report classes and Report methods options to define which declarations are to be reported.

Inspection options

Here you can find the description of settings available for the Declaration can have 'final' modifier inspection, and the reference of their default values.

Report classes

Not selected

Report methods

Not selected

Report fields

Default: Selected

Availability

By default bundled with

IntelliJ IDEA 2024.1, Qodana for JVM 2024.1,

Can be installed with plugin

Java, 241.18072

Last modified: 18 June 2024