Modifiables have an isInitialized method to make sure all required attributes have been set.
As an alternative to @Check could we expose isInitialized in the builder. The main reason @check won't work is if you want to reference instance objects which are not part of the immutable, which can be accessible to the builder.
Use case looks something like this:
@Immutable
public class Example {
Integer getValue();
public static class Builder extends ImmutableExample.Builder {
private final Validator validator;
public Builder(Validator validator) {
this.validator = validator
}
@Override public void build() {
if (isInitialized) {
validator.validate(this);
}
return super.build();
}
}
}
Modifiables have an isInitialized method to make sure all required attributes have been set.
As an alternative to
@Checkcould we expose isInitialized in the builder. The main reason @check won't work is if you want to reference instance objects which are not part of the immutable, which can be accessible to the builder.Use case looks something like this: