https://kotlinlang.org logo
Title
k

karelpeeters

03/21/2018, 2:13 PM
Is there a way to pass an array to a function that takes a vararg parameter? The spread operator passes a copy of the array, not the array itself. I encountered this problem when reading the docs of `Arrays.asList`:
Returns a fixed-size list backed by the specified array. (Changes to the returned list "write through" to the array.)
But it looks like using this property is not possible from Kotlin since you can't pass the real array.
m

muralimohan962

03/21/2018, 2:29 PM
fun foo(vararg items: Array<Type>) May be this should work.
d

diesieben07

03/21/2018, 2:30 PM
That's an "array of arrays".
m

muralimohan962

03/21/2018, 2:35 PM
Oh sorry.
s

spand

03/21/2018, 2:40 PM
I dont think you can in pure Kotlin and I can see why. I think you have to go through a java function to get the desired result.