record-builder icon indicating copy to clipboard operation
record-builder copied to clipboard

Support more Collection (and Map) types for immutable collections

Open JanecekPetr opened this issue 2 years ago • 3 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 :)

JanecekPetr avatar Apr 05 '23 22:04 JanecekPetr

A PR would be appreciated for this.

Randgalt avatar Apr 11 '23 08:04 Randgalt

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

pawellabaj avatar Jul 04 '23 19:07 pawellabaj

@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.

pawellabaj avatar Aug 05 '23 11:08 pawellabaj