Back to Intellij Community

ReplaceMapGetOrDefault

plugins/kotlin/code-insight/descriptions/resources-en/inspectionDescriptions/ReplaceMapGetOrDefault.html

2025.3-rc-2286 B
Original Source

Replaces map.getOrDefault(key, defaultValue) function calls with an indexing and elvis operator (map[key] ?: defaultValue).

Example:

fun test(map: Map<Int, String>) {
      map.getOrDefault(1, "foo")
  }
fun test(map: Map<Int, String>) {
      map[1] ?: "foo"
  }