Created
January 23, 2026 13:20
-
-
Save padymont/e150bc489e2f0f2dba6c5fae8a57ce41 to your computer and use it in GitHub Desktop.
Init Order
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
| // 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