问题
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. The would read:
class A {
Class<? extends SuperClass> a;
@Inject A(Class<? extends SuperClass> a) {
this.a = a.;
}
}
How can I correctly bind the parameter?
回答1:
Use this binding:
bind(new TypeLiteral<Class<? extends SuperClass>>() {})
.toInstance(SubClass.class);
来源:https://stackoverflow.com/questions/8734826/using-guice-how-can-i-inject-a-bounded-wildcard-class