Object literal can be converted to lambda
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") }
}
Inspection Details | |
---|---|
Available in: | IntelliJ IDEA 2023.3, Qodana for JVM 2023.3 |
Plugin: | Kotlin, @snapshot@ |
Last modified: 13 July 2023