November 2017
Intermediate to advanced
398 pages
10h 14m
English
With the introduction of functional programming in Java, the interest in and need for immutable objects increased. The functions passed into the methods may be executed in substantially different contexts than the one they were created in, so the need to decrease the chances of unexpected side effects made the case for immutability stronger. Besides, the Java way of creating an unmodifiable collection was quite verbose anyway, so the issue was addressed in Java 9. Here is an example of the code that creates an immutable collection of the Set interface in Java 8:
Set<String> set = new HashSet<>();set.add("Life");set.add("is");set.add("good!");set = Collections.unmodifiableSet(set);
After one does ...