Young Pups: New Collections APIs for Java 9 by Stuart Marks
Why Stack Overflow recommends it
Stack Overflow users link it when explaining the design reasoning behind Java 9's collection factory methods, including why they reject nulls and are immutable, straight from the person who designed them.
Recommended by 3 people across 3 different months, 2015 to 2020.
What it is
A conference talk from Devoxx 2015 in which Oracle's Stuart Marks, principal author of the Java 9 collection factory methods, presents the planned immutable collection implementations such as List.of, Set.of and Map.of. He covers why collection creation in Java is clumsy, the small API footprint of the new types, and their memory savings.
What people said
Recommends SKerkewitz · 2015-12 · Stack Overflow · on “Why doesn't Java have anonymous maps or arrays and lists?”
The video is about the new collection API improvements of Java 9. But in the beginning Stuart Marks explains why Java is not as convenient as other languages when it comes down to collection creation. [this video]
Recommends Nicolai Parlog · 2017-07 · Stack Overflow · on “Why does Map.of not allow null keys and values?”
As others pointed out, the Map contract [LINK] allows rejecting nulls... [S]ome implementations prohibit null keys and values [...]. Attempting to insert an ineligible key or value throws an unchecked exception, typically NullPointerException or ClassCastException . ... and the collection factories (not just on maps) make use of that [LINK] . They disallow null keys and values. Attempts to create them with null keys or values result in NullPointerException . But why? Allowing null in collections is by now seen as a design error. This has a variety of reasons. A good one is usability, where the most prominent trouble maker is Map::get . If it returns null , it is unclear whether the key is mi
Recommends Basil Bourque · 2018-07 · Stack Overflow · on “Converting array to list in Java”
FYI, to learn some of the technical details behind this, see *JEP 269: Convenience Factory Methods for Collections* [LINK] and a talk by Stuart Marks [this video] , the principal author.
Cites Eugene · 2020-07 · Stack Overflow · on “What are the java collections accepts adding null values?”
@GiorgiTsiklauri here you go [this video] : _generally regarded as a mistake_. You do know who Stuart Marks is, right? This is (1) and (2) is the fact that when you admit a mistake you do not it again (that is why immutable collections prohibit it)