Hossein Abbasi
Sep 7, 2018 · 1 min read

If you ever want to put an @Providesannotated method in the abstract class, it must be static.

What about in Kotlin?

Is it correct? :

@Provides
@Singleton
fun provideAppResources(context: Context): Resources {
return context.resources
}

Or

companion object {
@Provides
@Singleton
fun provideAppResources(context: Context): Resources {
return context.resources
}
}

Or

@Module
companion object {
@JvmStatic
@Provides
@Singleton
fun provideAppResources(context: Context): Resources {
return context.resources
}
}

Or none of them?!

Hossein Abbasi

Written by

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade