我花了一些时间想知道是否可以编写一个guice模块,它本身是用类型T参数化的,并使用它的类型参数来指定绑定.
就像在这个(不工作)的例子中一样:
interface A<T> {}
class AImpl<T> implements A<T>{}
interface B<T> {}
class BImpl<T> implements B<T> {}
class MyModule<T> extends AbstractModule {
@Override
protected void configure() {
bind(new TypeLiteral<A<T>>(){}).to(new TypeLiteral<AImpl<T>>(){});
bind(new TypeLiteral<B<T>>(){}).to(new TypeLiteral<BImpl<T>>(){});
}
}
Run Code Online (Sandbox Code Playgroud)
我尝试了不同的方法,尝试将T传递给MyModule作为Class/TypeLiteral的实例,但它们都没有工作.帮助赞赏.
此致,ŁukaszOsipiuk