Skip to content

Instantly share code, notes, and snippets.

@oucem
Forked from ajalt/example.kt
Created November 4, 2020 15:51
Show Gist options
  • Save oucem/ed12c6cd754ada2bba7a53ffbdfce050 to your computer and use it in GitHub Desktop.
Save oucem/ed12c6cd754ada2bba7a53ffbdfce050 to your computer and use it in GitHub Desktop.
Kotlin initializer order example
open class Parent {
private val a = println("Parent.a")
constructor(arg: Unit=println("Parent primary constructor default argument")) {
println("Parent primary constructor")
}
init {
println("Parent.init")
}
private val b = println("Parent.b")
}
class Child : Parent {
val a = println("Child.a")
init {
println("Child.init 1")
}
constructor(arg: Unit=println("Child primary constructor default argument")) : super() {
println("Child primary constructor")
}
val b = println("Child.b")
constructor(arg: Int, arg2:Unit= println("Child secondary constructor default argument")): this() {
println("Child secondary constructor")
}
init {
println("Child.init 2")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment