The Frontier logo The Frontier logo
06:53
Josh Skeen

SAM Type Conversion in Kotlin

Josh Skeen | Sep 17, 2018


What are SAM Type Conversions in Kotlin?

Just like Java 8, Kotlin supports SAM conversions. This means that Kotlin function literals can be automatically converted into implementations of Java interfaces with a single non-default method, as long as the parameter types of the interface method match the parameter types of the Kotlin function.

SAM type conversions allow interfaces which require an implementation of a single method to accept either an anonymous class or a lambda.

In this screencast...

In this screencast, we will recap on SAM Types, see how they work in Kotlin to support Java interoperability, and we'll also see some of the "gotchas" involved with the feature.

After this screencast, you'll be able to...

- Use SAM Type Conversions to write cleaner code for your Android applications

Prerequisites

Basic knowledge or experience building Android applications is recommended

Additional Resources

SAM Conversions
Kotlin Programming by Big Nerd Ranch