Using Guice, I want to inject a bounded-wildcard class. To be clear, I don't want to inject an object, but inject a class type. I think the constructor should look something like this:
class A {
class<?> a;
@Inject A(TypeLiteral<Class<? extends SuperClass>> a) {
this.a = a.getRawType();
}
}
Is the above code is correct? How can I bind the TypeLiteral?
Thanks to MForster at Stack Overflow for his answer:
Guice doesn't allow binding TypeLiteral. But it's unclear why you would want to inject a TypeLiteral in the first place.
Maybe this is what you want:
class A {
Class<? extends SuperClass> a;
@Inject A(Class<? extends SuperClass> a) {
this.a = a;
}
}
together with this binding:
bind(new TypeLiteral<Class<? extends SuperClass>>() {})
.toInstance(SubClass.class);