Trust final fields in records
chris.hegarty at oracle.com
Tue Jun 16 11:08:42 UTC 2020
> On 16 Jun 2020, at 11:08, Kasper Nielsen <kasperni at gmail.com> wrote:
>> One alternative might be an implicit static method parallel to the
>> constructor that
>> sets all field values, but does not execute any explicit constructor(s),
>> if present.
>> Sort of a 'raw' constructor.
> Not having a 'raw' constructor that breaks encapsulation is a feature,
> not an oversight .
Exactly. The creation of deserialized record objects through an invocation of the canonical constructor is intentional. That is the whole point of the Serializable records work [*].
>  https://cr.openjdk.java.net/~briangoetz/amber/serialization.html
More information about the valhalla-dev