https://kotlinlang.org logo
Title
c

codebeast

05/19/2017, 8:01 AM
Hey guys! Happy to be here 🙂 I have a JavaScript background and finding it difficult understanding the delegation concept as seen in the docs here:
class Person(val name: String) {
    constructor(name: String, parent: Person) : this(name) {
        parent.children.add(this)
    }
}
and here:
class MyView : View {
    constructor(ctx: Context) : super(ctx)

    constructor(ctx: Context, attrs: AttributeSet) : super(ctx, attrs)
}
Wondering if I could get a clearer description of what happens. Thanks
m

myanmarking

05/19/2017, 10:51 AM
codebeast: yo
you can also use constuctor overloads, like this
constructor(ctx: Context, attrs: AttributeSet = 0) : super(ctx, attrs)
with the annotation @JvmOverloads
k

kingsley

05/19/2017, 11:48 AM