karelpeeters
10/08/2018, 9:04 AMthis, and default parameters are evaluated in a constructor.Pavlo Liapota
10/08/2018, 9:12 AMclass Person(val name: String) {
constructor() : this(this.fun1())
fun fun1() = ""
}
Gives: Cannot access '<this>' before superclass constructor has been called 🙂Egor Trutenko
10/08/2018, 9:16 AMclass StateSensitive(
val someVal: Int = this.getState()
) {
private val state = 2
fun getState() = state
}
It's quite rough, but speaks for situation pretty much. state will be initialized after the resolution of someVal, so you can't access it, but still do.karelpeeters
10/08/2018, 9:17 AMEgor Trutenko
10/08/2018, 9:18 AMPavlo Liapota
10/08/2018, 9:18 AMthis anyway? Potentially no field will be initialized at this point.Egor Trutenko
10/08/2018, 9:19 AM