Skip to content

Instantly share code, notes, and snippets.

@abdurahmanadilovic
Last active January 27, 2018 07:30
Show Gist options
  • Save abdurahmanadilovic/82f15c844bf5641b7a5163f24fdf672a to your computer and use it in GitHub Desktop.
Save abdurahmanadilovic/82f15c844bf5641b7a5163f24fdf672a to your computer and use it in GitHub Desktop.
Kotlin secondary constructor
class SecondaryConstructor(){
val blog = "www.codingstoic.com"
val city = "Sarajevo"
constructor(aValue: Int) : this(){
println("a second constructor")
}
init{
println("inside the first init block")
println("blog is $blog and city is $city")
}
init{
println("inside the second init")
}
}
fun main(args: Array<String>) {
SecondaryConstructor(1)
}
// --- output ---
// inside the first init block
// blog is www.codingstoic.com and city is Sarajevo
// inside the second init
// a second constructor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment