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.

Regards,

Alberto.
________________________________
De: Kasper Nielsen <kaspe...@gmail.com>
Enviado: viernes, 21 de mayo de 2021 16:28
Para: Alberto Otero Rodríguez <albest...@hotmail.com>
Cc: core-libs-dev@openjdk.java.net <core-libs-dev@openjdk.java.net>
Asunto: Re: Java records used in enums

On Fri, 21 May 2021 at 14:51, Alberto Otero Rodríguez 
<albest...@hotmail.com<mailto:albest...@hotmail.com>> wrote:
Hi,

I think enums in Java should be immutable. When you let the programmer change 
values in an enum instance, an unexpected behaviour can happen when using 
multiple threads as enum instances are static (singleton).

So, I was wondering why not make enums instances be defined as records instead 
of normal classes.

Lots of reasons, for example:
* It would be a breaking change for an almost non-existent problem.
* All internal state of enums would now be public.
* Enum's extend java.lang.Enum, records extend java.lang.Record.
  java.lang.Enum cannot extend java.lang.Record because it has instance fields.

/Kasper

Reply via email to