-
Enhancement
-
Resolution: Unresolved
-
P4
-
None
-
None
-
generic
-
generic
A DESCRIPTION OF THE PROBLEM :
Background:
The lombok project is working on support for java 14/15 records.
In this case, the lombok Builder annotation allows a user to implement a builder pattern for a class with very little code. See: https://projectlombok.org/features/Builder
Tracking bug here:
https://github.com/rzwitserloot/lombok/issues/2356
The problem:
They have it mostly implemented, but the '@Builder.Default' annotation is running into a problem: There is no way to specify default values for a record's fields that works in the context of a lombok Builder.
Records do allow custom constructors and static factories but lombok generates all that for the developer normally. The records' fields are specified in a place that does not allow the developer to give them default values.
So we're kind of stuck. I would like a builder low-boilerplate pattern implementation for records that allows for default values without a lot of hassle, bit that seems clearly impossible without changes to the JDK.
Solutions:
At first I thought records just need the option to specify default values to the records' fields but then you quickly run into problems with the way constructors work. Unless java gains the ability to specify specific fields at new() time? That would work but not just impact records.
A second option would be to add the builder pattern to records directly. This is basically a poor man's version of option one but may be easier.
Background:
The lombok project is working on support for java 14/15 records.
In this case, the lombok Builder annotation allows a user to implement a builder pattern for a class with very little code. See: https://projectlombok.org/features/Builder
Tracking bug here:
https://github.com/rzwitserloot/lombok/issues/2356
The problem:
They have it mostly implemented, but the '@Builder.Default' annotation is running into a problem: There is no way to specify default values for a record's fields that works in the context of a lombok Builder.
Records do allow custom constructors and static factories but lombok generates all that for the developer normally. The records' fields are specified in a place that does not allow the developer to give them default values.
So we're kind of stuck. I would like a builder low-boilerplate pattern implementation for records that allows for default values without a lot of hassle, bit that seems clearly impossible without changes to the JDK.
Solutions:
At first I thought records just need the option to specify default values to the records' fields but then you quickly run into problems with the way constructors work. Unless java gains the ability to specify specific fields at new() time? That would work but not just impact records.
A second option would be to add the builder pattern to records directly. This is basically a poor man's version of option one but may be easier.