January 2018
Intermediate to advanced
434 pages
14h 1m
English
Let's go through the following steps, where we demonstrate how to pass a variable number of arguments to a function:
fun main(args: Array<String>) { someMethod("as","you","know","this","works")}fun someMethod(vararg a: String) { for (a_ in a) { println(a_) }}
fun main(args: Array<String>) { val list = arrayOf("as","you","know","this","works") someMethod(*list)}fun someMethod(vararg a: String) { for (a_ in a) { println(a_) }}
So basically, vararg tells the compiler ...
Read now
Unlock full access