# Default arguments, @JvmOverloads, and call function via reflection

**URL:** <https://discuss.kotlinlang.org/t/default-arguments-jvmoverloads-and-call-function-via-reflection/6675>\
**Category:** Support\
**Created:** [February 17, 2018, 11:46pm UTC](https://discuss.kotlinlang.org/t/default-arguments-jvmoverloads-and-call-function-via-reflection/6675 "2018-02-17T23:46:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![pidiobr](https://avatars.discourse-cdn.com/v4/letter/p/c89c15/32.png) [@pidiobr](https://discuss.kotlinlang.org/u/pidiobr)\
**Post date:** [February 17, 2018, 11:46pm UTC](https://discuss.kotlinlang.org/t/default-arguments-jvmoverloads-and-call-function-via-reflection/6675/1 "2018-02-17T23:46:51Z")

</div>

Hello, I would like to ask, how call (by reflection) function with default parameters from java:

If I have function like:

@JvmOverloads  
fun fun1(par1: Int = 1, par2: Int = 2, par3: Int = 3) { /_…_/ }

So this will generate:

fun1()  
fun1(par1)  
fun1(par1, par2)  
fun1(par1, par2, par3)

When I am invoking fun1 wihout parameters, it working …  
And question is: How can I invoke, for example, fun1 only with par3 - witch function signature can I use?  
Thank you very much.

---

<div class="post-metadata">

**Author:** ![tieskedh](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/tieskedh/32/2816_2.png) [@tieskedh](https://discuss.kotlinlang.org/u/tieskedh)\
**Post date:** [February 18, 2018, 12:18am UTC](https://discuss.kotlinlang.org/t/default-arguments-jvmoverloads-and-call-function-via-reflection/6675/2 "2018-02-18T00:18:12Z")

</div>

for all the combinations, you need three method names.

```
@JvmOverloads
fun fun1(par1 : Int = 1, par2: Int = 2, par3: Int = 3) {...}
@JvmOverloads
fun fun2(par2: Int, par3: Int = 3) = fun1(par2 = par2, par3 = par3)
fun fun3(par1: Int, par3: Int) = fun1(par1 = par1, par3 = par3)
fun fun3(par3: Int) = fun1(par3 = par3)

```

If you want the jvm-names in reversed order or any other order, you have bad luck and must implement it by yourself

---

<div class="post-metadata">

**Author:** ![pidiobr](https://avatars.discourse-cdn.com/v4/letter/p/c89c15/32.png) [@pidiobr](https://discuss.kotlinlang.org/u/pidiobr)\
**Post date:** [February 18, 2018, 10:37pm UTC](https://discuss.kotlinlang.org/t/default-arguments-jvmoverloads-and-call-function-via-reflection/6675/3 "2018-02-18T22:37:37Z")

</div>

Thank you. In fact there are many classes which call API. Theese classes are CGLIBed on runtime, so I cannot make combination for every function with default values. I was afarid, that this will not be easy if even possiible.
