Details Explanation of java.util.Set enhancement in Java 9

The Set.of() static factory methods provide a convenient way to create immutable sets. The Set instances created by these methods have the following characteristics:

They are structurally immutable. Elements cannot be added or removed. Calling any mutator method will always cause UnsupportedOperationException to be thrown. However, if the contained elements are themselves mutable, this may cause the Set to behave inconsistently or its contents to appear to change.

They disallow null elements. Attempts to create them with null elements result in NullPointerException.

They are serializable if all elements are serializable.

They reject duplicate elements at creation time. Duplicate elements passed to a static factory method result in IllegalArgumentException.

The iteration order of set elements is unspecified and is subject to change.

They are value-based. Callers should make no assumptions about the identity of the returned instances. Factories are free to create new instances or reuse existing ones. Therefore, identity-sensitive operations on these instances (reference equality (==), identity hash code, and synchronization) are unreliable and should be avoided.

JavaDeveloperZone is the group of innovative software developers. We are expert in Java JEE and BigData application development. Our contributions will help Java developers and make development journey easy. Feel free to ask any question and suggestion. Always have space for improvement !
We are also providing software application development as service. Contact us