In this lecture we examine immutable collections in Java 9+: the factory methods
List.of,
Set.of,
Map.of and
Map.ofEntries. We will compare them with the wrappers
Collections.unmodifiableList, discuss limitations (no mutations, no
null, no duplicates for a set and for map keys), element order, and performance. We will look at the limit of
10 pairs for
Map.of and typical exceptions:
UnsupportedOperationException,
NullPointerException,
IllegalArgumentException. Plus practical examples of when such collections simplify design and improve read-side thread safety.