# How to assign a java method with overload to a variable

**URL:** <https://discuss.kotlinlang.org/t/how-to-assign-a-java-method-with-overload-to-a-variable/3514>\
**Category:** Android\
**Created:** [June 27, 2017, 7:20am UTC](https://discuss.kotlinlang.org/t/how-to-assign-a-java-method-with-overload-to-a-variable/3514 "2017-06-27T07:20:28Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![joshuaavalon](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/joshuaavalon/32/2934_2.png) [@joshuaavalon](https://discuss.kotlinlang.org/u/joshuaavalon)\
**Post date:** [June 27, 2017, 7:20am UTC](https://discuss.kotlinlang.org/t/how-to-assign-a-java-method-with-overload-to-a-variable/3514/1 "2017-06-27T07:20:28Z")

</div>

```auto
// None of the following functions can be called with the arguments supplied.
val log: (String, String, Throwable) -> Unit = Log::e

// Unexpected token
val log: (String!, String!, Throwable!) -> Unit = Log::e

// Overload resolution ambiguity. All these functions match.
val log = Log::e

```

Is that a way to assign overload java method to a variable?

---

<div class="post-metadata">

**Author:** ![yole](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/yole/32/1425_2.png) [@yole](https://discuss.kotlinlang.org/u/yole)\
**Post date:** [June 27, 2017, 8:41am UTC](https://discuss.kotlinlang.org/t/how-to-assign-a-java-method-with-overload-to-a-variable/3514/2 "2017-06-27T08:41:08Z")

</div>

The error message shown by Kotlin is misleading in this case. The first declaration is not accepted because `Log.e` returns `Int`, not `Unit`. The following declaration works correctly:

```
val log: (String, String, Throwable) -> Int = Log::e

```

---

<div class="post-metadata">

**Author:** ![joshuaavalon](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/joshuaavalon/32/2934_2.png) [@joshuaavalon](https://discuss.kotlinlang.org/u/joshuaavalon)\
**Post date:** [June 27, 2017, 9:02am UTC](https://discuss.kotlinlang.org/t/how-to-assign-a-java-method-with-overload-to-a-variable/3514/3 "2017-06-27T09:02:19Z")

</div>

I feel stupid now. I have never noticed Log.e has a return value
