when invoking a constructor of a super class, how ...
# getting-started
b
when invoking a constructor of a super class, how can I acces the this of the child class? I'd like to do something along the lines of
Copy code
class AClass : SuperClass({this.log()}) {
    fun log() {
        console.log("boom")
    }
}
1
k
You can't call instance methods in that context, because at the point in time when you call the super class constructor, your
this
instance has not been constructed yet.
plus1 1
b
thank you for clarifying
z
If you don't need access to the instance, you can instead define the method in a companion object
b
I think there are some languages that allow it and some don't
was not sure 🙂
d
Some languages do, and it usually causes problems.