Closed Hsilgos closed 2 years ago
In-constructor field init is the only option for @Immutable
structs. The reason is Java syntax: final
fields with in-field default values cannot be (re)assigned with non-default values in the ctor body.
My guess is that mutable structs were made to have in-ctor init for consistency reasons.
So there is no alternative for @Immutable
structs. For mutable ones we could create a new per-field attribute for enabling in-field init selectively.
Superseded by https://github.com/heremaps/gluecodium/issues/1295
Currently fields with default parameters are set in generated constructor. It's desirable to investigate possibility to generate initialisation in place. Such approval had its own advantages like priority order of initialisation, optimisation and so on.