Android annotations - entering a superclass list

I am trying to execute the following Spring code using Android annotations:

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

I tried to use both the interface and the class.

Bean definition:

 @EBean public AbstractHandler implements Handler {} 

Attempt to enter:

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

But the following error always occurred:

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

So, I think, since the list itself is not annotated with @EBean , it cannot be used as a Bean ... to somehow implement this using Android annotations?

Thanks!

+6
source share
1 answer

Sorry, I can’t comment, but my reputation is too low.

I read the wiki , and when using the method based method, I saw how you enter beans. What I see in your code is that you are actually creating an EBean with an AbstractHandler object, however you are trying to embed a List object that was not annotated with @EBean, you can either remove the List <> and just use AbstractHandler or you can Extend the List implementation (like ArrayList) and annotate it with @EBean.

 @EBean public class InjectableArrayList<T> extends ArrayList<T>{} 

Hope this helps.

+2
source

Source: https://habr.com/ru/post/1014049/


All Articles