J'ai des problèmes génériques bizarres de kotlin avec Dagger que j'ai corrigés mais la solution n'est pas bonne.Pourquoi ne peut pas poignarder ces génériques kotlin?
est ici les classes de poignard:
@Module class P5Module {
@Provides fun pool(): RecyclerView.RecycledViewPool = RecyclerView.RecycledViewPool()
@Provides
fun adapters(fusion: P5FusionAdapter, personas: P5ListAdapter, skills: P5SkillsAdapter, info: InfoAdapter)
: List<Pageable> = listOf(fusion, personas, skills, info)
}
@ActivityScope
@Subcomponent(modules = arrayOf(P5Module::class)) interface P5Component {
fun adapter(): PageableAdapter
}
interface Pageable {
fun manager(ctx: Context): LayoutManager
fun attach()
fun adapter(): Adapter<*>
}
class PageableAdapter
@Inject constructor(val pageables: List<Pageable>, val pool: RecyclerView.RecycledViewPool) :PagerAdapter()
Quand je construis, je reçois cette erreur de KAPT dans le composant de niveau supérieur:
e: C:\Users\daykm\StudioProjects\P5Executioner\app\build\tmp\kapt3\stubs\appDebug\com\daykm\p5executioner\AppComponent.java:17: error: [com.daykm.p5executioner.main.P5Component.adapter()] java.util.List<? extends com.daykm.p5executioner.view.Pageable> cannot be provided without an @Provides-annotated method.
e:
e: public abstract interface AppComponent {
e: ^
e: java.util.List<? extends com.daykm.p5executioner.view.Pageable> is injected at
e: com.daykm.p5executioner.view.PageableAdapter.<init>(pageables, …)
e: com.daykm.p5executioner.view.PageableAdapter is provided at
e: com.daykm.p5executioner.main.P5Component.adapter()
e: java.lang.IllegalStateException: failed to analyze: org.jetbrains.kotlin.kapt3.diagnostic.KaptError: Error while annotation processing
Je pris un coup d'oeil aux bouchons:
@javax.inject.Inject()
public PageableAdapter(@org.jetbrains.annotations.NotNull()
java.util.List<? extends com.daykm.p5executioner.view.Pageable> pageables, @org.jetbrains.annotations.NotNull()
android.support.v7.widget.RecyclerView.RecycledViewPool pool) {
super();
}
@org.jetbrains.annotations.NotNull()
@dagger.Provides()
public final java.util.List<com.daykm.p5executioner.view.Pageable> adapters(@org.jetbrains.annotations.NotNull()
Apparemment ne correspond pas avec parce que quand je modifie la classe de poignard comme si:
@Module class P5Module {
@Provides fun pool(): RecyclerView.RecycledViewPool = RecyclerView.RecycledViewPool()
@Provides
fun adapters(fusion: P5FusionAdapter, personas: P5ListAdapter, skills: P5SkillsAdapter, info: InfoAdapter)
: List<*> = listOf(fusion, personas, skills, info)
}
@ActivityScope
@Subcomponent(modules = arrayOf(P5Module::class)) interface P5Component {
fun adapter(): PageableAdapter
}
interface Pageable {
fun manager(ctx: Context): LayoutManager
fun attach()
fun adapter(): Adapter<*>
}
class PageableAdapter
@Inject constructor(val pageables: List<*>, val pool: RecyclerView.RecycledViewPool) :PagerAdapter()
Le problème disparaît. Est-ce que je me heurte à un problème de traduction étrange avec la covariance et la contravariance? Je préfère ne pas forcer un casting en aval.
Oups, n'a pas trouvé cela jusqu'à ce que j'ai écrit ma réponse, mais https://stackoverflow.com/a/43149382 est un peu plus détaillée. – ephemient