min
09/08/2026, 7:02 AMopen class Inheritance {
open val xs: MutableList<Int> = mutableListOf()
}
class Inheritor: Inheritance() {
override val xs: MutableList<Int> = mutableListOf(0)
}
Instantiating Inheritor doesn’t allocate twice for xs because that doesn’t initialise super.xs, right?Marat Akhin
09/08/2026, 8:27 AMMarat Akhin
09/08/2026, 8:36 AMMarat Akhin
09/08/2026, 8:37 AMmin
09/08/2026, 8:47 AMfun main() {
open class Super {
open val x: Unit = Unit
init { println(this.x) }
}
object: Super() {
override val x = Unit
}
}
The field is uninitialised but the mutableListOf function is still called?min
09/08/2026, 8:49 AMfun main() {
open class Super {
open val x: Unit = myFactoryFunc()
init { println(this.x) }
}
object: Super() {
override val x = myFactoryFunc()
}
}
fun myFactoryFunc(): Unit {
println("myFactoryFunc")
}
Oh wow, it actually does.Marat Akhin
09/08/2026, 8:50 AMMarat Akhin
09/08/2026, 8:50 AMMarat Akhin
09/08/2026, 8:56 AMmin
09/08/2026, 9:04 AMMarat Akhin
09/08/2026, 9:05 AM