[Kotlin] Pass Kotlin Array as Java variable length argument [Java]

things to do

Pass Kotlin's ʻArray` to a function like this:

void hoge(HogeClass... hogeClasses) {
  /*abridgement*/
}

manner

You can do this by prepending * to ʻArray`, as shown below.

val hogeList: Array<HogeClass> = //Initialization omitted

//call
hoge(*hogeList)

What you are doing

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.

The site that I used as a reference

-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

[Kotlin] Pass Kotlin Array as Java variable length argument [Java]
[Java] array
Java array
Java array
Create variable length binary data in Java
java (array)
Java array
[Java] Array
Java array
java array
[Java] Array
[Java] Array notes
Java variable scope (scope)
java variable declaration
Java variable scope