(Note: there is a potential spoiler for one of the Kotlin koans below.)
For a higher order function that takes a function literal as follows:
fun <K, V> buildMap(build: MutableMap<K, V>.() -> Unit): Map<K, V> {
val map = HashMap<K, V>()
map.build()
return map
}
How is it that java.util.HashMap satisfies the interface MutableMapit is aiming at build? Does Kotlin support any duck style, or is it a special case in Kotlin's language only for certain classes that are part of the JDK?
I looked at the Kotlin documentation for interfaces and searched a bit, but could not find anything that seemed to explain this.
source
share