Pass Kotlin's ʻArray` to a function like this:
void hoge(HogeClass... hogeClasses) {
/*abridgement*/
}
You can do this by prepending *
to ʻArray`, as shown below.
val hogeList: Array<HogeClass> = //Initialization omitted
//call
hoge(*hogeList)
The *
supplemented at the beginning is the Spread operator, which is passed by expanding ʻArray`.
In Kotlin you can use variadic arguments by declaring fuga (vararg hoge: HogeClass)
, but you have to do the same when passing ʻArray` here.
-Variadic arguments and format of Kotlin -Note 2 Blog -[Variadic arguments (Variadics)](https://dogwood008.github.io/kotlin-web-site-ja/docs/reference/functions.html#%E5%8F%AF%E5%A4% 89% E9% 95% B7% E5% BC% 95% E6% 95% B0% E5% 8F% AF% E5% A4% 89% E5% BC% 95% E6% 95% B0-varargs)
Recommended Posts