Level 1 · Apprentice0 XP
Reuse behaviour without inheritance, and properties that compute, observe or load lazily.
Step 1 / 5
ProblemYou want a list that logs every addition. Inheriting from ArrayList ties you to its internals. Composing means writing thirty one-line methods that forward to the inner list, and maintaining them.
← → step
Before this: Generics, in, out and reified
🛠️ Your turn
Reading is not the skill, doing is. Try for ten minutes before you open the hint. Getting stuck first is what makes the solution stick.
1.Write a CountingSet<T> that implements MutableSet<T> by delegating to a HashSet and counts how many elements were ever added. Then give a class a lazy property that prints when it is computed, and read it twice to see it print once.