Of course the constructors of classes should be ab...
# getting-started
k
Of course the constructors of classes should be able to access
this
, and default parameters are evaluated in a constructor.
p
Copy code
class Person(val name: String) {
    constructor() : this(this.fun1())
    
    fun fun1() = ""
}
Gives:
Cannot access '<this>' before superclass constructor has been called
🙂
e
This is not the same. It is purely linking outer source to the inner state, this is what Kotlin's feature of defining properties in the very constructor is for. But imagine the following:
Copy code
class 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.
k
There is no "outer" at all, default parameter are evaluated in the class.
e
If you instantiate a field with a value, which was supplied in constructor parameter, then the latter is pretty much "outer"
p
But why would you like to access
this
anyway? Potentially no field will be initialized at this point.
e
Exactly ^