Use cases for java annotation and more

PuNisHeR

New Member
as far as i know, the only way to make the annotation take effect is reflection. Without reflection, java annotation become useless. Is this right?\[code\]public class Main{ @SomeAnnotation(name="some",value="http://stackoverflow.com/questions/11515833/annotation") public void method(){ //do something. } public static void main(String...args){ Main main = new Main(); //Just call the method directly, How to make the @SomeAnnotation make sense? main.method(); }}\[/code\]For instance, you first get a java Method object, then check all the annotations presented. And if you get what you want, then invoke the method by reflection. eg.\[code\]Method.invoke(Object, Object...args) \[/code\]People say annotation can reduce the tedious XML, but back to the XML configuration, the use pattern likes we load and parse the XML file, when we call some method ,we first get or check configuration info, then do the real stuff. How to achieve this by Annotation? The only way we got is reflection?
 
Back
Top