Java records used in enums

Kasper Nielsen kasperni at gmail.com
Fri May 21 15:31:38 UTC 2021


On Fri, 21 May 2021 at 16:00, Alberto Otero Rodríguez <albest512 at hotmail.com>
wrote:

> It seems a non-existent problem until you face it, which is what happened
> me today.
>
> I think at least (supposing enums can't be records) all the fields in
> enums should be made final by default.
>

A suppressible compiler warning on non-final enum fields would probably be
the best bet.

You can actually find some build-in types where the intended behavior is
final
but it was not declared. For example, java.sql.JDBCType [1]. And a couple
of
other internal classes.

/Kasper

[1]
https://github.com/openjdk/jdk/blob/master/src/java.sql/share/classes/java/sql/JDBCType.java


More information about the core-libs-dev mailing list