Skip to content

Instantly share code, notes, and snippets.

@MortezaNedaei
Last active April 14, 2022 09:08
Show Gist options
  • Save MortezaNedaei/7b6d2d8def0c57a865ee8c2b607c826e to your computer and use it in GitHub Desktop.
Save MortezaNedaei/7b6d2d8def0c57a865ee8c2b607c826e to your computer and use it in GitHub Desktop.
Kotlin SAM Conversion (SAM Interface)

❓ What is Kotlin SAM and fun interface?

✅ fun interface is Kotlin definition of Java functional interface. Kotlin can sugarize any Java Functional interfaces (interfaces with only one abstract member) into lambdas to leverage interoperability. This process is called SAM Conversion.

⁉️ Usage: It can help make your code more concise and readable by using lambda expressions.

⚠️ Tip: suspend function cannot be used as a SAM

⚡️ Examples: Comparator, ReadOnlyProperty, PropertyDelegateProvider interfaces

Kotlin-SAM-Conversion

More info: 1, 2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment