Using Guice, how can I inject a bounded-wildcard class?

我的梦境 提交于 2019-12-21 23:41:00

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!