Add support for a builder with required components#206
Add support for a builder with required components#206fredyw wants to merge 2 commits intoRandgalt:masterfrom
Conversation
When the record components are annotated with `@RecordBuilder.Required`, the builder method will take the required record components as its parameters. This is particularly useful to ensure that the builder is always populated with the required fields at compile-time instead of relying on a runtime validation. Example: ``` public record MyRecord(@required int a, @required int b, int c) @generated("io.soabase.recordbuilder.core.RecordBuilder") public class MyRecordBuilder { ... @generated("io.soabase.recordbuilder.core.RecordBuilder") public static MyRecordBuilder builder(int a, int b) { return new MyRecordBuilder().a(a).b(b); } ... } ```
4ba9d44 to
747b252
Compare
|
If the arguments/parameters are required, we should not include the no-arg tbh - I'm not sure I'm in favor of this. Anyone else? |
I agree that the no-arg |
|
This will get very complex quickly. RecordBuilder has so many combinations of options, etc. For example, try this: The |
|
This is where staged builders shine for me. Gives compile safety of must specify parameters without turning your builder constructor into a copy of the actual object constructor. |
When the record components are annotated with
@RecordBuilder.Required, the builder method will take the required record components as its parameters. This is particularly useful to ensure that the builder is always populated with the required fields at compile-time instead of relying on a runtime validation.Example: