-
-
Save oucem/ed12c6cd754ada2bba7a53ffbdfce050 to your computer and use it in GitHub Desktop.
Kotlin initializer order example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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