Back to Intellij Community

ObjectLiteralToLambda

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

2025.3-rc-2478 B
Original Source

Reports anonymous object literals implementing a Java interface with a single abstract method that can be converted into a call with a lambda expression.

Example:

class SomeService {
  val threadPool = Executors.newCachedThreadPool()

  fun foo() {
    threadPool.submit(object : Runnable {
      override fun run() {
        println("hello")
      }
    })
  }
}

After the quick-fix is applied:

fun foo() {
    threadPool.submit { println("hello") }
  }