KT.LATEINIT_USAGE

Usage of the lateinit modifier

Turn on this rule to flag usages of the lateinit modifier. Using lateinit for property initialization can be error-prone and the actual initialization is not guaranteed. Try using constructor injection or delegation to initialize properties.

Noncompliant Code

Copy
class Foo {
    private lateinit var i1: Int
    lateinit var i2: Int
}

Options

  • excludes (default: ['**/test/**', '**/androidtest/**', '**/commontest/**', '**/jvmtest/**', '**/jstest/**', '**/iostest/**'])

    path filters

  • ignoreOnClassesPattern (default: ``)

    Allows you to disable the rule for a list of classes

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