Effective Kotlin: Item 18 — Favor composition over inheritance

In item 18 of Joshua Bloch’s Effective Java he talks about using composition using forwarding classes to avoid the fragility of implementation inheritance. Of course in the Java world this can require a fair amount of code as each method of a class or interface typically needs a forwarding method unless you are creating a new API.

Kotlin fortunately saves us from this boiler-plate code through it’s implementation by delegation and means we can generate the books example ForwardingSet in one line: