withDefault

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

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.

Since Kotlin

1.1

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

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.

Since Kotlin

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

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.

Since Kotlin

1.0

@JvmName(name = "withDefaultMutable")
fun <K, V> MutableMap<K, V>.withDefault(defaultValue: (key: K) -> V): MutableMap<K, V>(source)

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.

Since Kotlin

1.0