A functional interface, declared with theDocumentation Index
Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
Use this file to discover all available pages before exploring further.
fun modifier, is an interface that contains exactly one abstract method. Also known as a Single Abstract Method (SAM) interface, it explicitly opts into SAM conversion. This compiler feature allows the interface to be instantiated using a concise lambda expression whose signature matches the abstract method, bypassing the need for verbose anonymous object expressions.
Declaration Syntax
To define a functional interface, prepend the standard interface keyword with the fun modifier.
fun interface:
- Single Abstract Method: It must declare exactly one abstract method.
- Multiple Implemented Methods: It may contain any number of non-abstract methods (methods with default implementations).
- No State: Like standard interfaces, it cannot maintain state (no backing fields).
- Subtyping: It can implement other standard interfaces, provided the resulting contract still yields exactly one abstract method.
fun modifier, a Kotlin interface must be instantiated using an object expression. When the fun modifier is present, the compiler automatically maps a lambda expression to the single abstract method.
fun interface creates a distinct, nominal type.
fun interface is nominally typed, the compiler guarantees type safety by preventing implicit casting between identical function signatures that belong to different functional interfaces.
Java Interoperability
Kotlin automatically applies SAM conversion to Java interfaces that contain a single abstract method (e.g., Runnable, Callable). The fun interface construct exists specifically to enable this same lambda-instantiation behavior for interfaces defined natively in Kotlin.
Master Kotlin with Deep Grasping Methodology!Learn More





