Empty collections by default using RecordInterface #152
Labels
enhancement
New feature or request
good first issue
Good for newcomers
PR welcome
A PR submitted for this issue would be welcome
My goal: Never to get a
null
from any Collection-like component.Currently there's the
useImmutableCollections
option for this, however that's not perfect. First of all, it does not work with SortedSet / NavigableSet / SortedMap / NavigableMap, but also e.g. Guava's collections types (#151). Also the record's canonical constructor can still be used directly, circumventing record-builder, and that makes any guarantees shaky. One more problem: collection copying has a cost, and our team actually decided to not useuseImmutableCollections
by default, so in our case it would not help even it all the previous reasons were void.One can use the Validation API, but again that can be circumvented.
Therefore, the only way to make this work all the time is to manually write checks:
This of course works, but it's a relatively big piece of manual code that has to be in every record.
Would be nice if record-builder did this out-of-the box for
@RecordInterface
-generated records. No more nulls, ever!The text was updated successfully, but these errors were encountered: