Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
takashno opened this issue Apr 2, 2025 · 0 comments · May be fixed by #21019
Open

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

takashno opened this issue Apr 2, 2025 · 0 comments · May be fixed by #21019

Comments

@takashno
Copy link
Contributor

takashno commented Apr 2, 2025

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant