September 2018
Intermediate to advanced
462 pages
13h 28m
English
In order to rectify the currently required code's verbosity in creating collections, we need library APIs for creating collection instances. Look at our earlier code snippet from 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:
Read now
Unlock full access