Chuck,
   It seems you are getting the annotation for the class itself and
not the method.
What worked for me was the following:
1. You need to get to the method. I used:
   MyOwnAnnotationExample.class.getMethod passing it a string
containing the name of the method, followed by the types of the
parameters (as Class types).
2. When you have the method, you can used the reflection API's
getAnnotations or
   getDeclaredAnnotations (they both seemed to work for me) called on
the
   Method object returned from getMethod.

Does anybody know of a better way to get the Method object for the
current method?

Regards,
Steve

On Oct 28, 8:11 am, "C.E. Thornton" <[EMAIL PROTECTED]> wrote:
> For 1107 -- Annotations
>
> I added a class for RequestForEnhancement and
> added a reflection API to display it -- But all I get
> is the reviewer again??
>
>  I used getDeclaredAnnotation() which is supposed
> to get the method annotations for the Class??
>
> ===================================================
> Reflected with:
>
> Annotation[] declaredAnnotations = c.getDeclaredAnnotations();
> int numberDeclaredAnnotations = declaredAnnotations.length;
> System.out.println("Class " + c.getName() + " has " +
>        numberDeclaredAnnotations + " declaredAnnotations");
>
> for (int i = 0 ; i < numberDeclaredAnnotations; i++) {
>        System.out.println("Annotation " + i + ": " +                    
> declaredAnnotations[i] +  ", type" + 
> declaredAnnotations[i].annotationType().getName());
>
> }
>
> =========================================================
> Claas Defined:
>
> import java.lang.annotation.*;
>
> @Retention(RetentionPolicy.RUNTIME)
> public @interface RequestForEnhancement {
>     int id();
>     String synopsis();
>     String engineer() default "[unassigned]";
>     String date()     default "[unimplemented]";
>
> }
>
> ====================================================
> Used as:
>
> @RequestForEnhancement(id=120, synopsis="Test Version",   
> engineer="Thornton", date="Jan 1,2009")
>    public void setId(int id) {
>         this.id = id;
>     }
>
> Help would be appreciated!
>
> Chuck T.
>
> --
> Competency and chastity have much in common,
> they both encompass their own punishment!
>
> -- C.E. Thornton -- Hawthorne Press --

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to