Skip to content

Instantly share code, notes, and snippets.

@blipinsk blipinsk/Component.kt
Last active Jul 22, 2019

Embed
What would you like to do?
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
You can’t perform that action at this time.