Are companion objects initialized when the class i...
# getting-started
a
Are companion objects initialized when the class is loaded? i.e if i run some code in the
init
method of the companion object does it fire as soon as the base class is classloaded?
d
How are you loading the class?
If you're referencing the object itself, then init will be called for sure.
s
Yes, companion object of given class are initialized as soon as the class containing it is loaded: https://kotlinlang.org/docs/object-declarations.html#semantic-difference-between-object-expressions-and-declarations