I do extensions function which will be all numbers with null translates to zero. I did a type cast, added "UNCHECKED_CAST" as the warning went, but the idea that you can somehow make it all easier (that is, I did it all wrong) does not let go.
fun main(args: Array<String>) { var i1: Int? = null var i2: Int = i1.fixNull() print(i2) } @Suppress("UNCHECKED_CAST") fun <T : Number> T?.fixNull(): T { if (this == null) return 0 as T return this }