# Kotlin function default arguments from java

**URL:** https://discuss.kotlinlang.org/t/kotlin-function-default-arguments-from-java/783
**Category:** Uncategorized
**Created:** [June 27, 2013, 5:13pm UTC](https://discuss.kotlinlang.org/t/kotlin-function-default-arguments-from-java/783 "2013-06-27T17:13:17Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![m.h.shams](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/m.h.shams/32/1482_2.png) [@m.h.shams](https://discuss.kotlinlang.org/u/m.h.shams)
#### Post date: [June 27, 2013, 5:13pm UTC](https://discuss.kotlinlang.org/t/kotlin-function-default-arguments-from-java/783/1 "2013-06-27T17:13:17Z")

</div>

given following Kotlin class:

```kotlin
    class Foo {
       public fun bar(i: Int = 0): Int = 2 * i
    }

```

How should I call 'bar' function without any parameter from a java/groovy code?

```kotlin
    def f = new Foo()
    f.bar() //throws:  java.lang.IllegalArgumentException: Parameter specified as non-null contains null
```

---

<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: [June 27, 2013, 7:38pm UTC](https://discuss.kotlinlang.org/t/kotlin-function-default-arguments-from-java/783/2 "2013-06-27T19:38:41Z")

</div>

I highly suspect that when Groovy silently passes null whenever the user didn't supply enough arguments. The best way is to pass the value explicitly.

The way Kotlin implements default arguments is by having an extra function with an extra parameter, and this is not what you want to use from Java/Groovy.

---

<div class="post-metadata">

### Author: ![mochadwi](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/mochadwi/32/5282_2.png) [@mochadwi](https://discuss.kotlinlang.org/u/mochadwi)
#### Post date: [December 30, 2019, 3:53am UTC](https://discuss.kotlinlang.org/t/kotlin-function-default-arguments-from-java/783/3 "2019-12-30T03:53:01Z")

</div>

For those curious for the solutions to this question, we can use `@JvmOverloads` annotation. As stated [here](https://stackoverflow.com/a/34518024/3763032) the original author continue the discussion on StackOverflow instead.
