Skip to content

Instantly share code, notes, and snippets.

@blipinsk
Last active July 22, 2019 05:30
Show Gist options
  • Save blipinsk/4fa5afbbe1aaf158450e5ac44904ee9a to your computer and use it in GitHub Desktop.
Save blipinsk/4fa5afbbe1aaf158450e5ac44904ee9a to your computer and use it in GitHub Desktop.
Dagger NPE issue: [Kotlin + Generics + Abstract classes]
package com.barteklipinski.example.daggernpe
import dagger.Component
import javax.inject.Singleton
@Singleton
@Component(
modules = [Module::class]
)
interface Component {
fun inject(root: Parent<ExampleInterface>)
}
package com.barteklipinski.example.daggernpe
import javax.inject.Inject
interface ExampleInterface
abstract class Parent <T : ExampleInterface> {
@Inject
lateinit var exampleString : String
fun exampleInit() {
DaggerComponent.create().inject(this as Parent<ExampleInterface>)
}
}
abstract class Child<T : ExampleInterface> : Parent<T>() {
@Inject
lateinit var exampleList: List<String>
}
package com.barteklipinski.example.daggernpe
import dagger.Module
import dagger.Provides
import javax.inject.Singleton
@Module
class Module {
@Provides
@Singleton
fun provideExampleDependencyString(): String {
return "example"
}
@Provides
@Singleton
fun provideExampleDependencyList(): List<String> {
return listOf()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment