Non-final field in 'enum'
Reports non-final fields in enumeration types. Non-final fields introduce global mutable state, which is generally considered undesirable.
Example:
enum Enum {
FIRST("first"),
SECOND("second");
public String str;
Enum(String str) {
this.str = str;
}
}
After the quick-fix is applied:
enum Enum {
FIRST("first"),
SECOND("second");
public final String str;
Enum(String str) {
this.str = str;
}
}
Use the `Ignore fields that cannot be made 'final'` option to only warn on fields that can be made final using the quick-fix.
Inspection options
Option | Type | Default |
---|---|---|
Ignore fields that cannot be made 'final' | Checkbox | true |
Inspection Details | |
---|---|
Available in: | IntelliJ IDEA 2023.3, Qodana for JVM 2023.3 |
Plugin: | Java, 233.SNAPSHOT |
Last modified: 13 July 2023