https://kotlinlang.org logo
Title
s

Sudhir Singh Khanger

07/19/2018, 3:27 AM
If the class has a primary constructor, each secondary constructor needs to delegate to the primary constructor, either directly or indirectly through another secondary constructor(s). Delegation to another constructor of the same class is done using the this keyword:
class Person(val name: String) {
    constructor(name: String, parent: Person) : this(name) {
        parent.children.add(this)
    }
}
Are there any examples of direct and indirect delegation here? What is
parent.children.add(this)
?
s

spand

07/19/2018, 5:09 AM
parent
is a parameter