The constructor you are using is as follows:
public inline constructor(size: Int, init: (Int) -> T)
It takes an index that begins with0 for the array, so { i -> (i * i).toString() }with 0as an argument leads to 0.
You can check this with this code if there is any doubt:
fun main(args: Array<String>) {
val func: (Int) -> (String) = { i -> (i * i).toString() }
println(func(0))
}
source
share