r/java • • Mar 16 '21

Java 16 / JDK 16: General Availability

196 Upvotes

82 comments sorted by

View all comments

65

u/[deleted] Mar 16 '21

Finally I can start migrating from .collect(Collectors.toList()) to toList()

21

u/TheCountRushmore Mar 16 '21

Keep in mind that toList() returns an immutable list, but this might be exactly what you want.

14

u/kag0 Mar 16 '21

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.

1

u/[deleted] Mar 16 '21

Exactly, it breaks LSP. I prefer Guava collections for this reason.