KT.FORBIDDEN_METHOD_CALL

Forbidden method call

This rule allows to set a list of forbidden methods. This can be used to discourage the use of unstable, experimental or deprecated methods, especially for methods imported from external libraries. Detekt will then report all method invocations that are forbidden.

Noncompliant Code

Copy
import java.lang.System
fun main() {
    System.gc()
}

Options

  • methods (default: ['kotlin.io.print', 'kotlin.io.println'])

    List of fully qualified method signatures which are forbidden. Methods can be defined without full signature (i.e. java.time.LocalDate.now) which will report calls of all methods with this name or with full signature (i.e. java.time.LocalDate(java.time.Clock)) which would report only call with this concrete signature.

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