# How to invoke method with variant arguments of java?

**URL:** <https://discuss.kotlinlang.org/t/how-to-invoke-method-with-variant-arguments-of-java/1214>\
**Category:** Uncategorized\
**Created:** [April 11, 2012, 6:49am UTC](https://discuss.kotlinlang.org/t/how-to-invoke-method-with-variant-arguments-of-java/1214 "2012-04-11T06:49:05Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![outersky](https://avatars.discourse-cdn.com/v4/letter/o/7bcc69/32.png) [@outersky](https://discuss.kotlinlang.org/u/outersky)\
**Post date:** [April 11, 2012, 6:49am UTC](https://discuss.kotlinlang.org/t/how-to-invoke-method-with-variant-arguments-of-java/1214/1 "2012-04-11T06:49:05Z")

</div>

Hi all,

Now I have such a method in java:

&nbsp;&nbsp;public static void reload(ClassDefinition... definitions) throws UnmodifiableClassException, ClassNotFoundException {

&nbsp;&nbsp;instrumentation.redefineClasses(definitions);

&nbsp;&nbsp;}

and this in kotlin:

fun reload(vararg definitions:ClassDefinition){

&nbsp;&nbsp;SomeJavaClass.reload(definitions)

}

the kotlin compiler complains&nbsp;&nbsp;the java method need a parameter of type ClassDefinition , but not Array\<ClassDefinition\> .

Is this a bug ?

Thanks.

Outersky

---

<div class="post-metadata">

**Author:** ![cy6erGn0m](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/cy6ergn0m/32/1439_2.png) [@cy6erGn0m](https://discuss.kotlinlang.org/u/cy6erGn0m)\
**Post date:** [April 11, 2012, 3:02pm UTC](https://discuss.kotlinlang.org/t/how-to-invoke-method-with-variant-arguments-of-java/1214/2 "2012-04-11T15:02:53Z")

</div>

Looks like bug.. you can only call function only if you know how many parameters.. also note that this is not Kotlin-Java interoperability issue but any vararg parameter can't be used as argument..

```kotlin
fun t(vararg x : String) {
    t2(x)
}

fun t2(vararg y : String) {
  println(y.size)
}
```

This does not work because compiler trying to pass x as first parameter instead of the whole vararg

---

<div class="post-metadata">

**Author:** ![abreslav](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/abreslav/32/8279_2.png) [@abreslav](https://discuss.kotlinlang.org/u/abreslav)\
**Post date:** [April 12, 2012, 5:41pm UTC](https://discuss.kotlinlang.org/t/how-to-invoke-method-with-variant-arguments-of-java/1214/3 "2012-04-12T17:41:17Z")

</div>

In Kotlin, you can't pass an array where a vararg parameter is expected. Instead, you have to spread an array:

``

```kotlin

fun reload(vararg definitions:ClassDefinition){

    SomeJavaClass.reload(*definitions)
}

```

Unfortunately, the back-end does not suport this yet. It’s on the way, though.
