fun <K, V> Map<K, V>.withDefault( defaultValue: (key: K) -> V ): Map<K, V>
Returns a wrapper of this read-only map, having the implicit default value provided with the specified function defaultValue.
This implicit default value is used when the original map doesn't contain a value for the key specified and a value is obtained with Map.getValue function, for example when properties are delegated to the map.
When this map already has an implicit default value provided with a former call to withDefault, it is being replaced by this call.
@JvmName("withDefaultMutable") fun <K, V> MutableMap<K, V>.withDefault( defaultValue: (key: K) -> V ): MutableMap<K, V>
Returns a wrapper of this mutable map, having the implicit default value provided with the specified function defaultValue.
This implicit default value is used when the original map doesn't contain a value for the key specified and a value is obtained with Map.getValue function, for example when properties are delegated to the map.
When this map already has an implicit default value provided with a former call to withDefault, it is being replaced by this call.
© 2010–2020 JetBrains s.r.o. and Kotlin Programming Language contributors
Licensed under the Apache License, Version 2.0.
https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/with-default.html