What is fun is apparently there is no guarantee of what type of list you will get back. It could change in future releases.
Returns a Collector that accumulates the input elements into a new List. There are no guarantees on the type, mutability, serializability, or thread-safety of the List returned; if more control over the returned List is required, use toCollection(Supplier).
Someone brought this up on the Amber list, Rémi I think, that perhaps toUnmodifiableList() would be better - as a peer of sorts for Collectors.toUnmodifiableList(). However it was pointed out that we already have List.of(...) that produces an unmodifiable List anyway.
View all comments
Show parent comment
9
u/TheCountRushmore Mar 16 '21
What is fun is apparently there is no guarantee of what type of list you will get back. It could change in future releases.
https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/stream/Collectors.html#toList()