Randgalt / record-builder

Record builder generator for Java records

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Support more Collection (and Map) types for immutable collections

JanecekPetr opened this issue · comments

Namely, SortedSet and NavigableSet and SortedMap and NavigableMap. All of those have an unmodifiable wrapper available in Collections. While not ideal and slightly worse than the actually immutable copies available via List.copyOf and friends, it's way better to have an unmodifiable wrapper (and a collection initialized to empty when nothing is in) than having null.

This was really surprising to consistently get empty collections everywhere and suddenly there was a null because we changed a Set to SortedSet.

In a perfect world, there would be support for even more types, like what Immutables do: Multisets and Multimaps from Guava, BiMap, all ImmutableCollections, EnumMaps. But let's not jump there yet :)

A PR would be appreciated for this.

@JanecekPetr , you can use now unmodifiable views - see #154

@JanecekPetr workaround proposal: use AutoRecord with ARICE extension.

It supports the most important (all ?) interfaces from java.util and com.google.common.collect packages.
However, it requires a Guava library for generated records, so it won't suit everyone.