I have two java annotations, say XA and YA. Both have some method (). I parse the source code and retrieve the Annotation object. Now I would like to dynamically apply the annotation to the real type so that I can call the () method. How can I do this without instructions instanceof? I really want to avoid a source like a switch. I need something like this:
Annotation annotation = getAnnotation();
String annotationType = annotation.annotationType().getName();
?_? myAnnotation = (Class.forName(annotationType)) annotation;
annotation.method();
? _? means I don’t know what myAnnotation type will be. I cannot use the base class for my XA and YA annotations, since inheritance of annotations is not allowed. Or can I do it somehow?
Thanks for any suggestion or help.
source
share