Back to Intellij Community

ConvertPairConstructorToToFunction

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

2025.3-rc-2567 B
Original Source

Reports a Pair constructor invocation that can be replaced with a to() infix function call.

Explicit constructor invocations may add verbosity, especially if they are used multiple times. Replacing constructor calls with to() makes code easier to read and maintain.

Example:

val countries = mapOf(
      Pair("France", "Paris"),
      Pair("Spain", "Madrid"),
      Pair("Germany", "Berlin")
  )

After the quick-fix is applied:

val countries = mapOf(
      "France" to "Paris",
      "Spain" to "Madrid",
      "Germany" to "Berlin"
  )