Annotations are not read correctly
Hi, I have the following sample Annotation
package annotations;
import java.lang.annotation.Annotation;
/**
* @author Stefan Schuster
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public @interface NoticeAnnotation {
String name() default "anonymous";
String note() default "TODO";
}
And the following class that uses the annotation:
public class AnnotationsTest {
public static void main(String[] args) {
for(Method m : AnnotationsTest.class.getMethods())
{
if(m.isAnnotationPresent(NoticeAnnotation.class))
{
// Die Annotation ist vorhanden, auslesen des Methodennamens und
// der Parameter der Annotation
System.out.println("Die Methode " + m + " ist mit einer Notiz versehen:");
NoticeAnnotation na = m.getAnnotation(NoticeAnnotation.class);
System.out.println("Der Entwickler " + na.name() + " hat eine Notiz eingef齡t:");
System.out.println(na.note());
}
}
}
@NoticeAnnotation(
name = "Dagobert Developer",
note = "Diese Methode muss noch verbessert werden"
)
public void testMethode()
{
// not relevant
}
}
The problem is that the annotation is not found for any method, so the
part where the information about the annotation is printed is never called.
What am I missing, to me it looks like the sample from the annotations tutorial,
but it is not working...
Thanks in advance,
Stefan

