How Staged Builders work with @Builder(style = BuilderStyle.STAGED)
masterA Staged Builder enforces a specific order of property initialization using generated interfaces. This ensures type-safety by requiring properties to be set in the exact order they are declared. If a property is marked with @Opt, it becomes optional and is grouped into a single interface that allows the user to call .build() immediately after the required properties are set.
import org.jilt.Builder;
import org.jilt.BuilderStyle;
import org.jilt.Opt;
@Builder(style = BuilderStyle.STAGED)
public final class Person {
public final String name;
public final boolean isAdult;
public Person(String name, boolean isAdult) {
this.name = name;
this.isAdult = isAdult;
}
}
// Usage:
// Person p = PersonBuilder.person().name("John").isAdult(true).build();