I want to know what exactly an asterisk does before a variable name in Kotlin.
I saw this (*args
) in a Spring boot Kotlin example:
@SpringBootApp
In addition to the answers that were directly towards "what is this thing!?!", you often have the case where you have a List
and want to pass it to a function that is expecting a vararg
. For this, the conversion is:
someFunc(x, y, *myList.toTypedArray())
Assuming that last parameter of someFunc
is vararg
of the same type as the elements in the list.