On Dec 2, 12:19 am, "Rene Erwee" <[EMAIL PROTECTED]> wrote:
> Hi
>
> I am battling to get my annotation read at method-level. I can get my
> program to read it at class-level, but when I annotate my Runtime
> Annotation with @Target(ElementType.METHOD) and move the
> RequestForEnhancement annotation to just above my method, my program
> says I have 0 annotations.
>
> Is the error in the code below? How should I change it or what can I do
> so that my program can read the annotation for the method?
Rene,
Vitor's suggestion will do the job but there is a way that does not
involve "hard coding" the method name.
Try something like this after you have the class object "c".
//Get all the methods of the class
Method[] methods = c.getDeclaredMethods();
//Check each method for annotations
for (Method m: methods) {
Annotation[] methodAnnotations = m.getAnnotations();
//An array length of 0 means the method has no annotations
//...otherwise print them using similar code as for class
annotations...
I hope this suggestion is helpful.
--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/javaprogrammingwithpassion?hl=en
-~----------~----~----~----~------~----~------~--~---