Back to Intellij Community

NonFinalFieldInEnum

java/java-impl/resources/inspectionDescriptions/NonFinalFieldInEnum.html

2025.3-rc-2607 B
Original Source

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.