Skip to content

Instantly share code, notes, and snippets.

@padymont
Created January 23, 2026 13:20
Show Gist options
  • Select an option

  • Save padymont/e150bc489e2f0f2dba6c5fae8a57ce41 to your computer and use it in GitHub Desktop.

Select an option

Save padymont/e150bc489e2f0f2dba6c5fae8a57ce41 to your computer and use it in GitHub Desktop.
Init Order
// What is the output of the function?
fun main() {
Habr()
}
class Habr {
init {
searchMagnit()
}
constructor() {
println("constructor")
}
init {
println("init")
}
val name: String
get() {
println("Get name")
return this::class.java.simpleName
}
companion object {
init {
println("companion init")
}
fun searchMagnit() {
println("Search Magnit")
}
}
}
// Output:
// companion init
// Search Magnit
// init
// constructor
// What is be the output now?
fun main() {
Habr.searchMagnit()
}
// Output:
// companion init
// Search Magnit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment