Safe cast operator (as?) throws exception

Warning: Unchecked cast: Any to T

This is caused by type erasure.

Try:

inline fun <reified T> cast(from: Any): T? = from as? T
5 Likes