Scrivio Interview library
LeadershipPrincipal7 min read · updated 12 November 2026

The Collections Framework of 1998 chose optional operations that throw UnsupportedOperationException instead of separate read-only interfaces. Looking at how Java evolved since, what were the consequences, and what would you standardise in your own APIs?

Choosing optional operations kept the framework to one small, learnable set of interfaces, and that simplicity is a large part of why it succeeded. The price is that mutability is invisible in the types, so unmodifiable lists are discovered only when something throws at run time, and later additions such as List.of, List.copyOf and Stream.toList had to keep the same approach for compatibility, while sequenced collections showed the framework can still grow through new interfaces and default methods. In my own APIs I would document mutability, return unmodifiable collections and never mutate inputs unless the contract says so.

Background to this question

Design decisions in a platform library live for decades. The Collections Framework of 1998 is still the most used API in Java, and every decision in it has had twenty-five years to show its effects. Looking back at one of them is a good way for a senior engineer to show judgement: what did the choice buy, what did it cost, how did it constrain later work, and what should we learn for the libraries our own teams publish. In this answer, we will recap the decision, look at what it gained, follow its costs through the later history of Java, and then turn the lessons into rules for company APIs.

1A Quick Recap of the Decision

The framework defines one List interface, one Set, one Map. Methods that change a collection, such as add, remove, set and clear, are documented as optional operations. A collection that does not support one of them throws UnsupportedOperationException. The other path, which the designers considered and rejected, was a separate interface for each level of mutability, such as an unmodifiable list, a fixed-size list and a modifiable list, repeated for every collection type and every kind of view.

Their reasoning was about size. Once we count unmodifiable, fixed-size, append-only and modifiable variants, across lists, sets, maps, queues and their views, the number of interfaces grows quickly, and some real collections would still not fit any of them. One interface per concept, with a documented way to refuse, was simpler.

2What the Decision Gained

The framework stayed small. A newcomer learns List, Set, Map and Queue and can use any collection in the JDK or in a library. Methods accept a List and work with ArrayList, LinkedList, Arrays.asList, an unmodifiable view or a custom list without overloads. Views such as subList, keySet and the result of Collections.unmodifiableList fit into the same types, so the whole ecosystem shares one vocabulary.

This mattered for adoption. Before 1998, Java had Vector and Hashtable and little else, and other libraries had very large collection hierarchies that were hard to learn. A compact framework that anyone could understand in an afternoon spread quickly, and the shared interfaces made libraries interoperate.

3What It Cost

The cost is that the type system cannot tell us whether a collection can be changed. A method declared to return List<Order> might return an ArrayList or an unmodifiable list, and the caller learns which only when add throws. The failure appears at run time, often in a different team's code, far from the place that chose to return an unmodifiable list.

Java
// Library version 1
public List<Order> openOrders() { return new ArrayList<>(orders); }
// Caller, written against version 1
List<Order> list = service.openOrders();
list.add(extraOrder); // works
// Library version 2: a reasonable change, same signature
public List<Order> openOrders() { return orders.stream().filter(Order::isOpen).toList(); }
list.add(extraOrder); // UnsupportedOperationException, at run time

Notice that the compiler accepted both versions and the caller's code. Nothing in the signature changed, yet the behaviour did. This is why returning a modifiable list is a commitment: once callers rely on it, switching to an unmodifiable one breaks them silently. Languages designed later, such as Kotlin with List and MutableList, or Scala with separate immutable and mutable packages, put the distinction into the types, and Guava's ImmutableList does the same as a class.

4How Later Java Kept the Same Approach

Each later addition had to fit the existing interfaces, because changing them would have broken every program. Java 9's List.of, Set.of and Map.of return unmodifiable collections typed simply as List, Set and Map. Java 10's List.copyOf and Collectors.toUnmodifiableList do the same. Java 16's Stream.toList returns an unmodifiable List too, which surprised many developers who expected the ArrayList that collect(Collectors.toList()) happens to give.

Java 21's sequenced collections are the most interesting case. They show the framework can still evolve: SequencedCollection was inserted as a new parent of List and Deque, and the new methods were added as default methods so most existing classes kept compiling. But addFirst and addLast are optional operations in exactly the 1998 style, and they throw on unmodifiable collections. The framework grew through new interfaces and default methods, not by revisiting the mutability decision.

Mutability across the history of the framework
ReleaseAdditionMutability in the type?
Java 1.2 (1998)List, Set, Map with optional operationsNo
Java 1.2Collections.unmodifiableList and friendsNo, a view typed as List
Java 9List.of, Set.of, Map.ofNo
Java 10List.copyOf, toUnmodifiableListNo
Java 16Stream.toListNo
Java 21SequencedCollection with addFirst, addLastNo; still optional operations
Every addition kept the original decision, because changing it would break existing code.

5What I Would Standardise in Our Own APIs

The first lesson is that a decision about a public type is permanent, so we should make the contract explicit even when the types cannot. I would require that every public method returning a collection documents whether the result is modifiable, and the default is unmodifiable: List.copyOf for state the library owns, Stream.toList for computed results. A caller who wants to change it makes their own copy. That keeps us free to change the implementation later, because nobody can come to rely on mutating our results.

The second rule covers inputs. A method never mutates a collection it receives unless its name and documentation say so, such as sortInPlace(list). Accepting a collection and quietly adding to it is the mirror image of the trap above. If a method needs to keep a collection it received, it copies it, so later changes by the caller cannot corrupt our state.

The third rule is to prefer the JDK interfaces over custom read-only types in shared APIs. A ReadOnlyList interface of our own might seem tempting, but every consumer would have to convert to and from it, and it would split us from the ecosystem. The better trade is the one the JDK made: standard interfaces, strict documented behaviour, and consistency, enforced in code review and with a small set of tests that check public methods do not return mutable internals.

6Follow-up questions

Would you use Guava's ImmutableList in a public API to get the guarantee in the type?

Inside one codebase it can work well, and some companies do it. In a library shared across many teams I would hesitate, because it ties every consumer to Guava and its version. Returning List and documenting that it is unmodifiable keeps consumers on JDK types only.

How do you test that an API returns an unmodifiable collection?

A simple test calls a mutator on the returned value and asserts UnsupportedOperationException. A stronger test also changes the library's internal state afterwards and checks that a previously returned list did not change, which catches unmodifiable views that still leak later changes.

Were optional operations a mistake?

I would call it a reasonable trade at the time. It gave Java a small, unified framework that the whole ecosystem adopted. With hindsight, the cost of run-time failures is real, and a new language would put mutability in the types, but changing it now would break too much code to be worth it.

7Conclusion

In this answer, we saw that optional operations kept the Collections Framework small and unified, which helped it spread, but left mutability invisible in the types, so unmodifiable collections fail only at run time. Every later addition, from List.of to Stream.toList and sequenced collections, kept that approach for compatibility while showing the framework can still grow through new interfaces and default methods. For our own APIs, the lesson is to make contracts explicit: document mutability, return unmodifiable collections by default, and never mutate inputs unless the contract says so.

What to say in the interviewAbout 90 seconds aloud

Open with

The 1998 choice was one interface per concept, with methods like add and remove marked optional so an implementation could throw UnsupportedOperationException instead of having separate read-only and modifiable interfaces.

Then, if they want more

The gain was a small framework that anyone could learn quickly, where every collection, view and wrapper shares the same types, and I think that is a big reason it was adopted so widely. The cost is that mutability is not visible in the type.

A caller cannot tell from List of Order whether add will work, and they find out at run time, often in another team's code. It also makes changes risky: if a library once returned an ArrayList and later returns Stream.toList, callers that added to it break with no compile error.

Java could not change this later without breaking everything, so List.of, copyOf and Stream.toList all return unmodifiable lists typed as plain List. Sequenced collections in Java 21 show the framework can still evolve, through a new parent interface and default methods, but addFirst is again an optional operation.

For our own APIs, I would standardise three things: document whether a returned collection is modifiable and default to unmodifiable, never mutate an input unless the method says so, and copy inputs we store. I would stick to JDK interfaces rather than custom read-only types.

About this answer

Last updated
12 November 2026
Versions it names
Java 10, Java 16, Java 21, Java 9
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "The Collections Framework of 1998 chose optional operations that throw...": https://scrivio-interview-library.netlify.app/java/collections-overview/aec64c15cb/