Hi all, I have a question. Why is an abstract val ...
# announcements
s
Hi all, I have a question. Why is an abstract val not initialized in the
init
block?
Copy code
abstract class Test() {
  abstract val test: String

  init {
    println(test)
  }

  fun print() = println(test)
}

class Test2() : Test() {
  override val test = "Hello world"
}

val test = Test2() // Output: "null"
test.print()       // Output: "Hello world”
In Java the same code would work when accessing an abstract method within the constructor. What is the same pattern in Kotlin?