April 2018
Intermediate to advanced
910 pages
33h 21m
English
In order to rectify the currently required code verbosity in creating collections, we need library APIs for creating collection instances. Look at our pre-Java 9 code snippet in the previous section and then consider this possible refactoring:
PlanetCollection<String> myPlanets = Set.of( "Earth", "Jupiter", "Mars", "Venus", "Saturn", "Mercury", "Neptune", "Uranus", "Dagobah", "Kobol");
This code is highly human-readable and not verbose.
The new implementation will include static factory methods on the following interfaces:
So, we are now able to create unmodifiable instances of List collections, Map collections, and Set collections. They can be instantiated with the following syntax: