Last active
July 22, 2019 05:30
-
-
Save blipinsk/4fa5afbbe1aaf158450e5ac44904ee9a to your computer and use it in GitHub Desktop.
Dagger NPE issue: [Kotlin + Generics + Abstract classes]
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.barteklipinski.example.daggernpe | |
import dagger.Component | |
import javax.inject.Singleton | |
@Singleton | |
@Component( | |
modules = [Module::class] | |
) | |
interface Component { | |
fun inject(root: Parent<ExampleInterface>) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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