In Kotlin, it warns you when calling an abstract function in a constructor, citing the following problematic code:
abstract class Base {
var code = calculate
It is definitely poor practice because you are invoking calculate()
on a partially constructed object. This suggests that your class has multiple phases of initialization.
If the result of calculation()
is used to initialize a member, or perform layout or something, you might consider using lazy initialization. This will defer the calculation of the result until the result is really needed.