すべてのサブクラスに共通のプロバイダーを実装しようとしています。いくつかのスキーマを想像してください:
SuperComponent.class
はComponentA.class
andの親ですComponentB.class
。私はプロバイダーを持っています:
@Provides
<T extends SuperComponent> List<T> providesComponents(Provider<T> provider) {
List<T> componentList = new ArrayList<>();
for (int i = 0; i < 5; i++) {
componentList.add(provider.get());
}
return componentList;
}
List<ComponentA>
アイデアは、オブジェクトおよび/またはList<ComponentB>
別のクラスのコンストラクターで必要なときに、このプロバイダーを呼び出すことです。次のようなものを想像してください。
public class ResourceManager {
List<ComponentA> componentAList;
List<ComponentB> componentBList;
@Inject
public ResourceManager(List<ComponentA> componentAList, List<ComponentB> componentBList) {
this.componentAList = componentAList;
this.componentBList = componentBList;
}
次のようなエラーが表示されます。
1) com.google.inject.Provider<T> cannot be used as a key; It is not fully specified.
どうすればそれを機能させることができますか?それぞれに異なるプロバイダーを作成できることはわかっていますがList<ComponentA>
、List <ComponentB>
実際にはコンポーネントの数が2よりもはるかに多いため、必要です...