Effective Kotlin: Item 27 — Eliminate unchecked warnings

In the excellent Effective Java, item 27 covers unchecked warnings with the main take-home being you should remove as many as you can. Kotlin already helps by reducing the potential number of warnings we get, for example, with its use of smart casts and star-projections instead of raw types.

if (obj is String) {
println(obj.length) // Smart-cast to a String automatically

Where you cannot remove a warning but know it to be type-safe then in Java you would annotate the class with…