https://kotlinlang.org logo
Title
r

Roberto Messina

09/19/2019, 8:36 AM
I don't understand why there is that error
s

spand

09/19/2019, 8:37 AM
Parameters cannot be reassigned
l

Luca Nicoletti

09/19/2019, 8:41 AM
parameters are considered to be
final
m

Matteo Mirk

09/19/2019, 8:46 AM
Roberto, you only need to create the array inside the function and return it, don’t pass it as a parameter. This way of using mutable “out parameters” is very C-style 🙂
r

Roberto Messina

09/19/2019, 8:49 AM
yes, cause i know C, C++ and C#
m

Matteo Mirk

09/19/2019, 11:08 AM
Right, there’s no need to do that in Kotlin, just remove the
v
parameter and return the one created inside the function. You can even shorten the declaration to:
fun loadArray(n: Int) = IntArray(n) {/*...*/}
function expressions and type inference can help shortening the code