d

    David

    3 years ago
    Hey @Sam - nah. It's a proper "high end" optimisation even for those Java users. I looked it up a while back and end up just doing the older style for my Kotlin modules and moved on. Be good to know if I was wrong on this point though? I think our time would be better spent turning things lazy if they need be and obvs not doing anything slow in the provisioning blocks.
    Although looking back at my code I did use a companion object 🤔 ...I also remember thinking that this must be redundant!
    s

    Sam

    3 years ago
    I tried few things, companion objects with @JvmStatic does help
    Dagger generated code being in Java is using the static version (generated by Kotlin compiler)
    and the DaggerAppComponent never creates an instance of the AppModule
    It wouldn't make sense if Dagger generated code is going to be in kotlin
    so far being in Java, seems to be fine
    d

    David

    3 years ago
    Ah nice! So if you are 💯 Kotlin then no effect but if you have Java then it remains valid?
    @Module
    open class SyncModule {
    
        @Module
        companion object {
            /**
             * Provide access to the notification manager.
             *
             * @return the notification manager.
             */
            @Provides
            @JvmStatic fun providesNotificationManager(context: Context): NotificationManager {
                return context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
            }
    ...
    ..snippet from one of my Kotlin modules
    s

    Sam

    3 years ago
    even if you are in Kotlin it will be fine as long as Dagger generated code is in Java
    In your case, look at the generated code of the component using the SyncModule
    it will be java based and will invoke providesNotificationManager as a static method on SyncModule
    d

    David

    3 years ago
    I see. Will do after I've made dinner - post back your findings in the main channel!
    s

    Sam

    3 years ago
    make sure to declare your SyncModule as abstract
    there is really no reason to create an instance of it
    and hence the optimization
    d

    David

    3 years ago
    Ah so that code wouldn't of had a chance either way. Facepalm. 😅
    Thanks for the tip!
    s

    Sam

    3 years ago
    Sure