Factory methods for SequencedSet and SequencedMap
Rafael Winterhalter
rafael.wth at gmail.com
Thu Jan 16 07:13:17 UTC 2025
Hello,
I am happily taking SequencedSet and SequencedMap into use, but one
inconvenience I encounter is the lack of factory methods for the two.
In code where many (initial) collections have zero or one element (for
later aggregation), I now write Set.of()/Set.of(one) and
Map.of()/Map.of(key, value), as it makes the code shorter and more
readable. Those collections are of course implicitly sequenced, but now I
must make the variable type of the surrounding monad Set and Map, and
simply assume that a LinkedHashSet or LinkedHashMap is used when a
collection of more than one element is set, without requiring the interface
type. This does not require any type casting, as I rely on the iteration
order only, but the code loses some of its expressiveness.
I did not find any discussion around introducing factories for
SequencedSet.of(...) and SequencedMap.of(...), similar to those that exist
in the Set and Map interfaces. Was this ever considered, and if not, could
it be?
Best regards, Rafael
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/core-libs-dev/attachments/20250116/e52adada/attachment-0001.htm>
More information about the core-libs-dev
mailing list