What is SAM Conversion in Kotlin?

Technology CommunityCategory: KotlinWhat is SAM Conversion in Kotlin?
VietMX Staff asked 3 years ago

“SAM” stands for “single abstract method”, and “SAM-type” refers to interfaces like Runnable, Callable.

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.

That means that when you call some Java method from Kotlin, and that method satisfies conditions described above, you can pass lambda or method reference instead.