# Kotlin Functional Interfaces: Function reference and SAM conversion

DevFeed: [Kotlin Functional Interfaces: Function reference and SAM conversion](<https://devfeed.tech/articles/kotlin-functional-interfaces-function-reference-and-sam-conversion-38640.md>)

Original publisher: [Read original article](<https://krossovochkin.com/posts/2020_10_17_kotlin_functional_interfaces_function_references_and_sam_conversion/>)

Published: 2020-10-17T00:00:00Z

Content type: tutorial

Language: en

Sources: [Vasya Drobushkov](<https://devfeed.tech/sources/vasya-drobushkov.md>)

Topics: [Kotlin](<https://devfeed.tech/topics/kotlin.md>), [callback](<https://devfeed.tech/topics/callback.md>), [interfaces](<https://devfeed.tech/topics/interfaces.md>), [function](<https://devfeed.tech/topics/function.md>), [Java](<https://devfeed.tech/topics/java.md>)

Tags: [bytecode](<https://devfeed.tech/tags/bytecode.md>), [callback](<https://devfeed.tech/tags/callback.md>), [class](<https://devfeed.tech/tags/class.md>), [code](<https://devfeed.tech/tags/code.md>), [function](<https://devfeed.tech/tags/function.md>), [function-reference](<https://devfeed.tech/tags/function-reference.md>), [functional](<https://devfeed.tech/tags/functional.md>), [interfaces](<https://devfeed.tech/tags/interfaces.md>), [interop](<https://devfeed.tech/tags/interop.md>), [introduction](<https://devfeed.tech/tags/introduction.md>), [java](<https://devfeed.tech/tags/java.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>)

## AI overview

This tutorial examines Kotlin functional interfaces, function references, and SAM conversion in a callback scenario. It explains that Kotlin 1.4 supports SAM conversion for functional interfaces, allowing callback objects to be created from function references. Although separate callback objects are created for different method calls, they delegate to the same function reference and the program behaves correctly; explicit callback instances can avoid repeated allocations.

## Source excerpt

Introduction About two years ago I made a post about a tricky case in Kotlin-Java interop related to the usage of function references and SAM conversion. One of the points there was that in Kotlin, if interface is declared instead of a function, one has to explicitly create an object, therefore no caveats as with interop: val callback = object : ThirdParty.Callback { override fun onValueChanged(value: Int) { this@App.onValueChanged(value) } } With Kotlin 1.4 there is now a "Functional interface" which supports SAM conversion. And I've been asked on how it works in a similar situation. Let's find out.