Abstract var

Similarly, you can have an abstract var, but then the subclass needs to supply a getter and a setter:

abstract class Base {
  abstract var something: Int
}

class SomethingSource : Base() {
  override var something: Int = 0
    get() = field
    set(value) { field = value}
}

fun main() {
  val source = SomethingSource()

  println(source.something)
  source.something = 1337
  println(source.something)
}

Prev Table of Contents Next

This book is licensed under the Creative Commons Attribution-ShareAlike 4.0 International license.