How staged builders work
masterStaged builders enforce a specific order of construction. When using BuilderMode.STAGED or BuilderMode.STANDARD_AND_STAGED, each record component must be built in order and specified via individual staged builders.
Staged Required Only Mode
Using BuilderMode.STAGED_REQUIRED_ONLY or BuilderMode.STANDARD_AND_STAGED_REQUIRED_ONLY creates a variant that only stages required components. The following are added to the final stage instead of being staged:
- Optional components (if
addConcreteSettersForOptionalis enabled). - Collections (if matching collection options are enabled).
- Components with initializers (if
skipStagingForInitializedComponentsis enabled).
@RecordBuilder.Options(builderMode = BuilderMode.STAGED)
public record MyRecord(String name, int age) {}