I spent some time wondering if it is possible to write a guice module which itself is parametrized with type T and uses its type parameter to specify bindings.
Like in this (not working) example:
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>>(){});
}
}
I tried different approaches passing trying to pass T to MyModule as instance of Class/TypeLiteral but none of them worked. Help appreciated.
Regards, ?ukasz Osipiuk
See Question&Answers more detail:os