Join Slack
Powered by
Are companion objects initialized when the class i...
# getting-started
a
Amo
08/20/2024, 4:09 PM
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
Daniel Pitts
08/20/2024, 4:20 PM
How are you loading the class?
Daniel Pitts
08/20/2024, 4:21 PM
If you're referencing the object itself, then init will be called for sure.
s
Szymon Jeziorski
08/21/2024, 7:28 AM
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
2
Views
Open in Slack
Previous
Next