Effective Kotlin: Item 28 — Prefer lists to arrays

Joshua Bloch in item 28 of Effective Java talks about why you should prefer lists to arrays by firstly highlighting some of their differences. Interestingly with Kotlin some of the differences no longer hold true because of its changes to the generic type system.

In Java, arrays are covariant meaning that where Sub is a subtype of Super an array of type Sub[] is a subtype of Super[] which can lead to an ArrayStoreException at runtime if you store a different subtype of Super in an array:

// runtime exception
Object[]…