Functional (SAM) interfaces
To declare a functional interface in Kotlin, use the modifier.
For functional interfaces, you can use SAM conversions that help make your code more concise and readable by using lambda expressions.
Instead of creating a class that implements a functional interface manually, you can use a lambda expression. With a SAM conversion, Kotlin can convert any lambda expression whose signature matches the signature of the interface’s single method into an instance of a class that implements the interface.
If you don’t use a SAM conversion, you will need to write code like this:
By leveraging Kotlin’s SAM conversion, you can write the following equivalent code instead:
A short lambda expression replaces all the unnecessary code.
Functional interfaces vs. type aliases
Functional interfaces and type aliases serve different purposes. Type aliases are just names for existing types – they don’t create a new type, while functional interfaces do.
Type aliases can have only one member, while functional interfaces can have multiple non-abstract members and one abstract member. Functional interfaces can also implement and extend other interfaces.
Considering the above, functional interfaces are more flexible and provide more capabilities than type aliases.