I really wish they hadn't implemented "immutable" lists as a normal List that throws unchecked exceptions on modification.
Would it have been that hard to add a ReadOnlyList interface with only the methods that don't throw? Now we've got a wonky compile-unsafe toList() in the standard library for all time.
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.
JavaFX provides a ReadOnlyObjectProperty which are then extended by ObjectProperty and it works perfectly fine. This isn't some radical, untested idea.
The List and collection APIs are poorly designed even beyond not providing a read only base. Why the hell would a list of generic type Cat contain a type of Dog?
65
u/[deleted] Mar 16 '21
Finally I can start migrating from
.collect(Collectors.toList())totoList()