Numbers cast

Report a typo

What will be the output of this program?

fun myFun(myList: MutableList<Any>): Int {
    var result = 0
    for (item in myList) {
        result += item as? Int ?: 0
    }
    return result
}

fun main() {
    val myList = mutableListOf<Any>("hello", 3, "world", 3, 1, 7.0, 20L, 3)
    println(myFun(myList))
}
Select one option from the list
___

Create a free account to access the full topic