Ken McDonald
06/06/2019, 2:18 PMShawn
06/06/2019, 2:20 PMinit
blocksKen McDonald
06/06/2019, 2:39 PMShawn
06/06/2019, 3:31 PMthis()
in the constructor declaration, before the actual body. Here’s a very contrived example lol:
class Foo(val a: Int) {
constructor(notA: String) : this(notA.length)
}
igor.wojda
06/06/2019, 3:31 PMinit
as body of primary constructor.
BTW If the class has no primary constructor, then each secondary constructor has to initialise the base type using the super
keyword, or to delegate to another constructor which does that.
open class Foo(val a: Int) {
}
class Bar : Foo {
constructor(a: Int) : super(a) {
}
constructor(a: Int, b: Int) : super(a) {
}
}
Ken McDonald
06/06/2019, 4:07 PM