You're trying to access class's annotations. Try something like this:
public class MyOwnAnnotationExample {
public static void main(String[] args) throws NoSuchMethodException {
MyOwnAnnotationExample c = new MyOwnAnnotationExample();
Method m = c.getClass().getMethod("doNothing", null);
System.out.println(m.getAnnotation(RequestForEnhancement.class).date());
System.out.println(m.getAnnotation(RequestForEnhancement.class).engineer());
System.out.println(m.getAnnotation(RequestForEnhancement.class).id());
System.out.println(m.getAnnotation(RequestForEnhancement.class).synopsis());
}
@RequestForEnhancement(
date="now",
engineer="Vitor",
id=001,
synopsis="bla bla"
)
public void doNothing() {
for (int j = 0; j<10; j++) {
int i = 0;
i = i + j;
}
}
}
On Mon, Dec 1, 2008 at 11: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?
>
>
>
> public void printAnnotations() {
>
> mae = new MyOwnAnnotationExample();
>
> Class c = mae.getClass();
>
> Annotation[] Annotations = c.getAnnotations(); //
> c.getDeclaredAnnotations() also does not work
>
> int numberOfAnnotations = Annotations.length;
>
>
>
> System.out.println("Class: " + c.getName() + " has " +
> numberOfAnnotations + " annotations");
>
>
>
> for (int i = 0; i < numberOfAnnotations; i++) {
>
> System.out.println("Annotation " + i + ": " + Annotations[i] +
>
> ", type" + Annotations[i].annotationType().getName());
>
>
>
> }
>
> }
>
>
>
> Thanks
>
>
>
>
>
> Kind regards
>
> * *
>
> *Rene Erwee*
>
> *Conveyancing Director***
>
> *EDELSTEIN-BOSMAN INC*
>
>
>
> 222 Lange Street
>
> New Muckleneuk
>
> Pretoria
>
>
>
> Tel: (012) 452 8900
>
> Fax: (012) 452 8901
>
> E-mail: [EMAIL PROTECTED] <[EMAIL PROTECTED]>
>
>
>
> This e-mail and any attachments are confidential and intended solely for
> the addressee and may also be privileged or exempt from disclosure under
> applicable law. If you are not the addressee, or have received this e-mail
> in error, please notify the sender immediately, delete it from your system
> and do not copy, disclose or otherwise act upon any part of this e-mail or
> its attachments.
>
> Internet communications are not guaranteed to be secure or virus-free.
> Edelstein-Bosman Inc does not accept responsibility for any loss arising from
> unauthorised access to, or interference with, any Internet communications
> by any third party, or from the transmission of any viruses. Replies to
> this e-mail may be monitored by Edelstein-Bosman Inc for operational or
> business reasons.
>
> Any opinion or other information in this e-mail or its attachments that
> does not relate to the business of Edelstein-Bosman Inc is personal to the
> sender and is not given or endorsed by Edelstein-Bosman Inc.
>
>
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---