SAM conversion on Kotlin Interfaces

From documentation:
SAM-conversions only work for Java methods, not supported for Kotlin functions, because Kotlin has nice functional types, and there’s no need for SAM conversion

But I could use them in one area. Lambdas do not support named arguments that well. With interfaces I can give more descriptive names to method and arguments. Also interfaces are better supported by documentation tools such as Dokka. That is really important for public API.

Also my code is written in Kotlin, but is consumed by Java users. People use it in combination with Java8 lambdas. With Kotlin lambdas IDE does not automatically add parameter names into Java8 lambdas. It works for interfaces.

So this forces me to use Java interfaces in Kotlin code. I would like to see SAM conversion enabled for Kotlin interfaces

4 Likes

See: https://youtrack.jetbrains.com/issue/KT-7770

And this: https://youtrack.jetbrains.com/issue/KT-9016

Bump: using Kotlin through JNA’s Callback also requires explicit interfaces which I would prefer to back with regular lambdas instead of anonymous classes. My only solution right now is to use ugly anonymous classes with intelliJ’s “hide this because its ugly as ...” feature.

Bump! This is really important! It shouldn’t make a difference if an interface is declared in Kotlin or in Java, I want SAM conversion on it.

3 Likes