Android注释 - 注入超类类型列表

Nom*_*fan 6 java spring android annotations

我正在尝试使用Android Annotations实现以下Spring代码:

@Autowired
public initHandlerList(List<Handler> handlerList) {
   // Do stuff with the list ...
}
Run Code Online (Sandbox Code Playgroud)

我尝试使用接口和类.

Bean定义:

@EBean
public AbstractHandler implements Handler {}
Run Code Online (Sandbox Code Playgroud)

试图注入:

@Bean
public initHandlersList(List<AbstractHandler> handlersList) {
  // Do stuff with the list ...
}
Run Code Online (Sandbox Code Playgroud)

但总是得到以下错误:

Error:(20, 5) error: org.androidannotations.annotations.Bean can only be used on an element annotated with @org.androidannotations.annotations.EBean
Run Code Online (Sandbox Code Playgroud)

所以我想因为列表本身没有注释,@EBean它不能用作Bean ...任何使用Android Annotations实现这一点的方法?

谢谢 !

Nor*_*ord 2

抱歉,我无法发表评论,但我的声誉太低了。

我阅读了wiki,在基于方法的注入下我看到了如何注入 bean。我在你的代码中看到的是,你确实正在使用 AbstractHandler 对象创建一个 EBean,但是你正在尝试注入一个尚未用 @EBean 注释的 List 对象,你可以删除 List<> 并只使用 AbstractHandler 或您可以扩展 List 实现(如 ArrayList)并使用 @EBean 对其进行注释。

@EBean
public class InjectableArrayList<T> extends ArrayList<T>{}
Run Code Online (Sandbox Code Playgroud)

希望这可以帮助。