Skip navigation links

Package java9.util

Provides a Java 8 backport of the JEP 269: Convenience Factory Methods for Collections that were introduced in Java 9.

See: Description

Package java9.util Description

Provides a Java 8 backport of the JEP 269: Convenience Factory Methods for Collections that were introduced in Java 9.

Unmodifiable collections

An unmodifiable collection is a collection, all of whose mutator methods are specified to throw UnsupportedOperationException. Such a collection thus cannot be modified by calling any methods on it. For a collection to be properly unmodifiable, any view collections derived from it must also be unmodifiable. For example, if a List is unmodifiable, the List returned by List.subList is also unmodifiable.

An unmodifiable collection is not necessarily immutable. If the contained elements are mutable, the entire collection is clearly mutable, even though it might be unmodifiable. For example, consider two unmodifiable lists containing mutable elements. The result of calling list1.equals(list2) might differ from one call to the next if the elements had been mutated, even though both lists are unmodifiable. However, if an unmodifiable collection contains all immutable elements, it can be considered effectively immutable.

Value-based Classes

Some classes, such as java.util.Optional, are value-based. Instances of a value-based class:

A program may produce unpredictable results if it attempts to distinguish two references to equal values of a value-based class, whether directly via reference equality or indirectly via an appeal to synchronization, identity hashing, serialization, or any other identity-sensitive mechanism. Use of such identity-sensitive operations on instances of value-based classes may have unpredictable effects and should be avoided.

Since:
9
Skip navigation links

Copyright © 2021. All rights reserved.