Closed Randgalt closed 3 years ago
@krzyk I believe this satisfies your request. I didn't see the point in only adding an initializer for collections.
cc @danp11
Very nice and Thanks for adding this!
Only thing Im thinking of is if it should be mentioned in RecordBuilder and in the JavaDoc for useImmutableCollections that @NotNull and interpretNotNullsPattern = true takes precedence over "or an empty immutable collection if the component is {@code null}."
Or maybe it is better to leave that out to not complicate things to much :-)
Thanks again for this PR.
@danp11 yeah - I think letting it alone is best. Maybe it can be improved in the future, who knows. If you use a combination of options maybe a different generation mode emerges.
Adds special handling for record components of type
java.util.List
,java.util.Set
,java.util.Map
andjava.util.Collection
. When the record is built, any components of these types are passed through an added shim method that uses the corresponding immutable collection (e.g.List.copyOf(o)
) or an empty immutable collection if the component is null.This is what the generated builder looks like: CollectionRecordBuilder.java
Closes #56 Closes #58