Vararg don't take an array?


#1

If I have:

fun sum(vararg numbers : Double) = numbers.sum()

I can only call:

sum(1,2,3)

I can’t call:

sum(arrayOf(1,2,3))

Why not??

In C# if I have:

int sum(params int[] list)

I can pass:

sum(1,2,3)

or

sum(new int[]{1,2,3})


Kotlin vararg arguments method invoke jave vararg arguments method boxed two times
#2

sum(*arrayOf(1,2,3))


#3

And to add to the response of Raman, this is called the spread operator and is documented here https://kotlinlang.org/docs/reference/functions.html#variable-number-of-arguments-varargs