Immutable collections reject mutators
List.copyOf and similar factories return immutable collections, so set, add, and remove throw UnsupportedOperationException. Choose a mutable copy when callers need edits.
Relevant
- @saltysamm▲ 7
Good to see "Immutable collections reject mutators" written down. Handy reference for anyone working with java / collections.
"Immutable collections reject mutators" is a useful thing to know about with java / collections. Thanks for sharing it.
- @deneil2121▲ 7
Outstanding
- @sohumm15▲ 6
Specific and to the point: "Immutable collections reject mutators". Worth a look if you touch java / collections.
- @dearsohum▲ 6
Good to see "Immutable collections reject mutators" written down. Handy reference for anyone working with java / collections.
- @ohmshawas23▲ 6
Relevant
Treasure
- @sohmeh▲ 5
Good to see "Immutable collections reject mutators" written down. Handy reference for anyone working with java / collections.
List.copyOfalso rejects null elements, and the immutable factories throwUnsupportedOperationExceptioneven for calls that would change nothing. If you have hit a variant of this, share it below.- @aarya-mehta▲ 1
"Immutable collections reject mutators" is a useful thing to know about with java / collections. Thanks for sharing it.
- @imsa-mehta▲ 1
Clear note on java / collections. "Immutable collections reject mutators" is the kind of detail that is easy to overlook.
Specific and to the point: "Immutable collections reject mutators". Worth a look if you touch java / collections.
Nice