Category
collections
Pattern slug
copying-collections-immutably
Which code is affected?
Collections.unmodifiableList(input)
Type of issue
This is not an equivalent replacement for the old code, because List.copyOf(Collection) copies the collection, whereas Collections.unmodifiableList(List) just wraps it in a read-only wrapper.
Describe the issue
The new method requires twice as much memory, and its execution time depends on the size of the input collection.
The memory utilization and execution time of the old method is constant and does not depend on the size of the input collection.
JDK version tested
9+
Category
collections
Pattern slug
copying-collections-immutably
Which code is affected?
Collections.unmodifiableList(input)Type of issue
This is not an equivalent replacement for the old code, because
List.copyOf(Collection)copies the collection, whereasCollections.unmodifiableList(List)just wraps it in a read-only wrapper.Describe the issue
The new method requires twice as much memory, and its execution time depends on the size of the input collection.
The memory utilization and execution time of the old method is constant and does not depend on the size of the input collection.
JDK version tested
9+