Kotlin HashMap withDefault()
Syntax & Examples


Syntax of HashMap.withDefault()

There are 2 variations for the syntax of HashMap.withDefault() extension function. They are:

1.
fun <K, V> Map<K, V>.withDefault( defaultValue: (key: K) -> V ): Map<K, V>

This extension function returns a wrapper of this read-only map, having the implicit default value provided with the specified function defaultValue.

2.
fun <K, V> MutableMap<K, V>.withDefault( defaultValue: (key: K) -> V ): MutableMap<K, V>

This extension function returns a wrapper of this mutable map, having the implicit default value provided with the specified function defaultValue.