Other than making it "work" with vararg that is
# announcements
j
Other than making it "work" with vararg that is
b
the spread operator AFAIK is a special case. All it does is create a new array that contains the elements of the one you spread and pass it as the vararg argument. The easiest way to see this is to got to “Show Kotlin Bytecode” and click on decompile
Copy code
val array = intArrayOf(1,2,3)
foo(*array)
// decompiled
int[] a = new int[]{1, 2, 3, 4, 5};
foo(Arrays.copyOf(a, a.length));
In case you have something like
foo(*array, 4)
the code gets a bit more complicated, but it still creates a new array with all the elements of array, but now it also adds 4.
👍 1
Also AFAIK the spread operator only works with arrays, not lists, you your code above won’t compile.