Skip to content

[REQ][JAVA][spring] Make enum fields final in generated Java code #21018

@takashno

Description

@takashno

Is your feature request related to a problem? Please describe.

Apologies for the minor suggestion, but I noticed that when generating Java enum classes using the spring generator, the fields representing the enum values are not declared as final. While this does not cause runtime issues, it goes against Java best practices for immutability and correctness. In idiomatic Java code, enum fields are typically declared as private final, ensuring they are immutable once initialized.

Describe the solution you'd like

I would like the code generation templates to be updated so that enum value fields are declared as private final. For example, the following generated code:

private String value;

should be updated to:

private final String value;

This change improves immutability and consistency with standard Java practices.

Describe alternatives you've considered

Manually updating the generated code after each generation (not ideal, especially in CI environments).
Using custom templates to override enum generation behavior (adds maintenance overhead).
Creating a post-processing script to modify the generated files (fragile and error-prone).

Additional context

Nothing...

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions