# Why Diffrence of annomous Impl of Interface declared in between Java and Kotlin

**URL:** <https://discuss.kotlinlang.org/t/why-diffrence-of-annomous-impl-of-interface-declared-in-between-java-and-kotlin/1641>\
**Category:** Uncategorized\
**Created:** [May 3, 2016, 2:19am UTC](https://discuss.kotlinlang.org/t/why-diffrence-of-annomous-impl-of-interface-declared-in-between-java-and-kotlin/1641 "2016-05-03T02:19:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ronnin](https://avatars.discourse-cdn.com/v4/letter/r/aca169/32.png) [@ronnin](https://discuss.kotlinlang.org/u/ronnin)\
**Post date:** [May 3, 2016, 2:19am UTC](https://discuss.kotlinlang.org/t/why-diffrence-of-annomous-impl-of-interface-declared-in-between-java-and-kotlin/1641/1 "2016-05-03T02:19:24Z")

</div>

inteface with only one method

1. declared in Java, annomous impl can writtern in closure form, like fun call

2. declared in Kotlin, annomous impl should use " object:".  
eg:

why ?

---

<div class="post-metadata">

**Author:** ![Dittert](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/dittert/32/1736_2.png) [@Dittert](https://discuss.kotlinlang.org/u/Dittert)\
**Post date:** [May 3, 2016, 6:29am UTC](https://discuss.kotlinlang.org/t/why-diffrence-of-annomous-impl-of-interface-declared-in-between-java-and-kotlin/1641/2 "2016-05-03T06:29:05Z")

</div>

This is called SAM conversion and Kotlin only supports this for Java interfaces and not for Kotlin code. The [documentation](https://kotlinlang.org/docs/reference/java-interop.html#sam-conversions) says:

> Also note that this feature works only for Java interop; since Kotlin has proper function types, automatic conversion of functions into implementations of Kotlin interfaces is unnecessary and therefore unsupported.

If you want to dig deeper into this, here are a two past discussions of this topic:

> [@Kotlin SAM traits as lambda functions](https://discuss.kotlinlang.org/t/kotlin-sam-traits-as-lambda-functions/279):
>
> around M5-M6 Kotlin gained support for calling java SAM's (Single Abstract Methods, think Runnable Interface) with a lambda function.&nbsp;&nbsp;This allowed you to do //kotlin code SwingUtilities.invokeLater{ &nbsp;&nbsp;//some code here } //is the same as this code SwingUtilities.invokeLater(object : Runnable { &nbsp;&nbsp;override fun run() { &nbsp;&nbsp;//some code here &nbsp;&nbsp;} }&nbsp;&nbsp; However if the SAM is a kotlin Trait, this does not work for some reason... are their plans to allow Kotlin SAM Traits to be called like Lambda'…

> [@Kotlin and SAM interface with two parameters](https://discuss.kotlinlang.org/t/kotlin-and-sam-interface-with-two-parameters/293):
>
> I'm trying to get a SAM with two parameters to work with a Kotlin closure. The best I could do is this: // Javapublic interface Two { &nbsp;&nbsp;Integer f(Integer i, String s);} // Kotlinfun f2(two: Two) {} fun test() { &nbsp;&nbsp;f2 ( Two { i, s -\> 42 } )} I expected to be able to write: f2 { i, s -\> 42 } Why do I need to explicitly coerce this expression to `Two`?

---

<div class="post-metadata">

**Author:** ![fvasco](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/fvasco/32/1961_2.png) [@fvasco](https://discuss.kotlinlang.org/u/fvasco)\
**Post date:** [May 3, 2016, 7:07am UTC](https://discuss.kotlinlang.org/t/why-diffrence-of-annomous-impl-of-interface-declared-in-between-java-and-kotlin/1641/3 "2016-05-03T07:07:13Z")

</div>

Java and Kotlin are 99% interoperable.

See [https://youtrack.jetbrains.com/issue/KT-7770](https://youtrack.jetbrains.com/issue/KT-7770)
