This inspection reports dangerous operations inside constructors including:
- Accessing a non-final property in constructor
- Calling a non-final function in constructor
- Using this as a function argument in a constructor of a non-final class
These operations are dangerous because your class can be inherited,
and a derived class is not yet initialized at this moment. Typical example:
abstract class Base {
val code = calculate()
abstract fun calculate(): Int
}
class Derived(private val x: Int) : Base() {
override fun calculate() = x
}
fun testIt() {
println(Derived(42).code) // Expected: 42, actual: 0
}