https://kotlinlang.org logo
Title
u

ursus

06/24/2018, 2:53 AM
I use dagger2 module, and in java I make all provider methods static for optimizing performance - not creating module instance. How can I make this in kotlin? companion objects always create its instance, or is compiler smart enough to not create the instance if all methods are @jvmstatic?
m

Max Russek

06/24/2018, 7:03 PM
While I think you are way over-optimizing, I think that companion objects compile to a separate singleton class with thread safe lazy initialization. All
@JvmStatic
methods will be static methods, which don’t trigger initialization of the singleton I believe. I could be wrong. Worst case you can write top-level functions
u

ursus

06/25/2018, 12:44 AM
from what I see companion objects are eager + still creates it regardless all methods being static, damn