Various technical articles, IT-related tutorials, software information, and development journals
Saturday, June 15, 2019
Kotlin won't create SAM literals of interfaces defined in Kotlin
In a recent Kotlin project I wrote an interface definition meant to be consumable from Java and possibly other Kotlin code. It contains only one method, so I expected it to be usable in Kotlin code as a Single Abstract Method implementation literal, e.g. SomeInterface { arg -> ... }. This didn't compile, noting that the interface type has no constructors. Apparently interfaces defined in Kotlin cannot be used in this fashion, possibly as an encouragement to just pass functions instead.
Labels:
java
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment