Learning init blocks and secondary constructors in Kotlin, I wrote this program to test the orders of which gets called first, but for some reason the secondary constructor never gets executed. I get the feeling that I’m missing something crucial here with my logic.
class Sample(private var s : String) { constructor(a: String, c: String): this(a) { this.s += c } init { s += "B" } val alphabet = s } fun main(){ val sample = Sample("A","C") print(sample.alphabet) }
I wanted to print ABC, but I only get AB.
submitted by /u/ED9898A
[link] [comments]