Android Developers
Published in

Android Developers

Dagger in Kotlin: gotchas and Optimizations

Illustration by Virginia Poltrack

kapt build improvements

Qualifiers for field attributes

@Inject @field:MinimumBalance lateinit var minimumBalance: BigDecimal
@Inject @MinimumBalance lateinit var minimumBalance: BigDecimal 
// @MinimumBalance is ignored!
@Inject @MinimumBalance lateinit var minimumBalance: BigDecimal 
// FIXED: @MinimumBalance is NOT ignored!

Static @Provides functions optimization

Injecting Generics

class MyVMFactory @Inject constructor(
private val vmMap: Map<String, @JvmSuppressWildcards Provider<ViewModel>>
) {
...
}

Inline method bodies

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store