You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It would be nice if same @Parameter fields used for of static factory methods were also be required as arguments of .builder(). This prevents the case where the user forgets a required argument when using the builder but doesn't find out about it until runtime. Example:
@Value.Immutable(buildersRequireParams=true)
abstractclassPerson {
@ParameterpublicabstractStringname();
publicabstractOptional<String> jobTitle();
}
finalMyClassfred = ImmutableMyClass.builder("Fred").build();
finalMyClasssally = ImmutableMyClass.builder("Fred").jobTitle("CEO").build();
// but not ImmutableMyClass.builder().jobTitle("CEO")
This would of course need to be turned on by a style.
The text was updated successfully, but these errors were encountered:
Thank you for the feature request! For some "gut feeling" reason, I would not conflate here constructor parameters and builder parameters, mostly because how it can be combined in a different way. Yes, we can introduce another one style attribute for this as you proposed, but we have a lot better chances to reuse existing functionality. We have builder module with annotations applicable to special static factory builders. Annotation @Builder.Parameter (and also @Builder.Switch just to mention) can only be used on parameters of a static method. I'll played a bit with code so it will work now for attributes and I guess annotation name reveals the intent well. Oh yeah, it would be funny to see an attribute with two annotations @Value.Parameter @Builder.Parameter if used together. After experimenting with the code I also found out that we cannot remove parameter-less builder() method or make it private because quite few other generators depends on this convention and changing them would be too painful, so builder() method (and separate initializers for attributes turned into parameters) were made package-private.
You can try latest snapshot/build from sources to check this out. Remember to add org.immutables:builder module with annotations as a compile dependency.
It would be nice if same
@Parameter
fields used forof
static factory methods were also be required as arguments of.builder()
. This prevents the case where the user forgets a required argument when using the builder but doesn't find out about it until runtime. Example:This would of course need to be turned on by a style.
The text was updated successfully, but these errors were encountered: