unmodifiable view
A wrapper around a collection that rejects writes but still shows changes the owner makes to the underlying collection.
In more detail
An unmodifiable view stops callers modifying your data, but they can still see it change later. If a caller must get a stable snapshot, give them a defensive copy instead.
Example
Collections.unmodifiableList(items)Related terms
- defensive copy — A copy of a mutable object, such as a list, made when it crosses a boundary so the other side cannot change your data.
- mutable state — Data that can change after it is created, such as a field that is reassigned or a list that is added to.
Taught in
- The Collections Framework — Modern Java: Virtual Threads & High-Throughput Services
- Scope, var And Immutable Objects — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Lists, Sets, Maps, Deques And Sequenced Collections — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep