casting - Java annotation dynamic typecast -


i have 2 java annotation types, let's xa , ya. both have method(). parse source code , retrieve annotation object. i'd dynamicaly cast annotation real type of able call method(). how can without instanceof statement? want avoid switch-like source. need this:

annotation annotation = getannotation(); // recieve annotation object here string annotationtype = annotation.annotationtype().getname();  ?_? myannotation = (class.forname(annotationtype)) annotation; annotation.method(); // need, method() called 

?_? means have no idea myannotation type. cannot use base class xa , ya annotations since inheritance in annotations not allowed. or possible somehow?

thanks suggestion or help.

why don't use typesafe way retrieve annotation ?

final yourannotationtype annotation = classtype.getannotation(yourannotationtype.class); annotation.yourmethod(); 

if annotation can't found, null returned.

please note works fields , methods.


Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -