I am trying to achieve the following Spring code using Android Annotations:
@Autowired
public initHandlerList(List<Handler> handlerList) {
// Do stuff with the list ...
}
I tried using both an interface and a class.
Bean definition:
@EBean
public AbstractHandler implements Handler {}
Trying to inject:
@Bean
public initHandlersList(List<AbstractHandler> handlersList) {
// Do stuff with the list ...
}
But always got the following error:
Error:(20, 5) error: org.androidannotations.annotations.Bean can only be used on an element annotated with @org.androidannotations.annotations.EBean
So I guess since the list itself is not annotated with @EBean
it can't be used as a Bean... any way to implement this using Android Annotations?
Thanks !
These annotations consist of multiple data members, names, values, pairs. These annotations can be applied to any place where a type is being used. For example, we can annotate the return type of a method. These are declared annotated with @Target annotation.
Simply place the annotation keyword in front of the class. As an example: Name the module gfg-annotations. Set the package to com.geeksforgeeks.gfg_annotations. Set the class name to AdapterModule. Set the language as kt or Kotlin. Image 3. Configuring the Module.
androidx.annotation:annotation:1.2.0 is released. Version 1.2.0 contains these commits. Major changes since 1.1.0 Added @ChecksSdkIntAtLeast annotation, which can be used to identify methods or fields used to gate access on SDK level and satisfy the NewApi lint check.
Four are imported from java.lang.annotation: @Retention, @Documented, @Target, and @Inherited. Three are included in java.lang: @Deprecated, @Override and @SuppressWarnings
Sorry I can't comment but my reputation is too low.
I read the wiki and under method based injection I saw how you inject the beans. What I can see in your code is that you are indeed creating a EBean with an AbstractHandler object however you are trying to inject a List object which has not been annotated with @EBean you can either delete the List<> and just use the AbstractHandler or you can extend a List implementation (Like ArrayList) and annotate it with @EBean.
@EBean
public class InjectableArrayList<T> extends ArrayList<T>{}
Hope this helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With