Practice ยท 3 of 3
Seal the Registry
Registry keeps a mutable index but exposes it safely.
Implement in Solution:
- static class Registry with put(String k, int v),
int get(String k) (missing โ throw NoSuchElementException),
Map<String, Integer> snapshot() (unmodifiable view),
and Map<String, Integer> frozenCopy() (independent immutable copy).
- static int totalOf(Map<String, Integer> values) summing the values โ
it must compile against either of the two exposure styles.
The test mutates the registry after taking a snapshot to prove the copy
stays independent.
Difficulty: intermediate
Press Submit to check your solution.
Back to lesson: Practice: Collections Lab