Tuesday, 15 February 2011

Java Reflection: Count of methods with an annotation? -


This works fine to filter methods with annotation:

 For  (Method Me: ParseTree.class.getMethods ()) {if (m.isnnotationPresent (Analyze.class)) { 

What if I just got a Counting, without looping? Is there any way to give a definite interpretation on how many methods of a particular class?

This is a very special case, so I doubt there is a way in the Java Refaction API .

But even if there is such a method, it will do the same: Repeat all the methods of a class, annotate and report the number.

I suggest that you can implement a static method for this task in some utility classes.

  Public static count annotationInclass (class  

No comments:

Post a Comment