KT.OBJECT_LITERAL_TO_LAMBDA

Anonymous object with implementation of a single method

An anonymous object that does nothing other than the implementation of a single method can be used as a lambda. See https://kotlinlang.org/docs/java-interop.html#sam-conversions See https://kotlinlang.org/docs/fun-interfaces.html

Noncompliant Code

Copy
object : Foo {
    override fun bar() {
    }
}

Compliant Code

Copy
Foo {
}

The content on this page is adapted from the Detekt Docs. Copyright ©2022 The Detekt Team. All rights reserved. https://detekt.dev/comments.html