r/java • • Mar 16 '21

Java 16 / JDK 16: General Availability

196 Upvotes

82 comments sorted by

View all comments

Show parent comments

13

u/TheCountRushmore Mar 16 '21

The problem is that you would want it to implement Collection and collection defines Collection#add

https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/Collection.html#add(E)

4

u/kag0 Mar 16 '21

True, maybe I should have suggested they create a ReadOnlyCollection (which would be useful other places where add throws UnsupportedOperationException).
Or hell, just have it return Iterable.

Anyway, I don't mean to suggest I have the answer. Just that this is probably the last option I would have picked.

1

u/minimingus Mar 16 '21

Look into vavr collections

3

u/kag0 Mar 16 '21

I love me some vavr, all the way back when it was javaslang. In this case though I'm talking about what gets shipped in the core library, and I don't think they'd ever add a (scala/kotlin style) separate immutable persistent collections library (as much as I'd like them to).

1

u/minimingus Mar 16 '21

Yeah i don’t think it will ever get added due to backward compatibility...