Back to Intellij Community

JavaMapForEach

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

2025.3-rc-2441 B
Original Source

Reports a Java Map.forEach method call that can be replaced with Kotlin's forEach.

Example:

fun test(map: HashMap<Int, String>) {
      map.forEach { key, value ->
          foo(key, value)
      }
  }

  fun foo(i: Int, s: String) {}

The quick-fix adds parentheses:

fun test(map: HashMap<Int, String>) {
      map.forEach { (key, value) ->
          foo(key, value)
      }
  }

  fun foo(i: Int, s: String) {}