I would like to use annotations in my application. For this reason I create "hello world" for annotations:
follows example:
public class HelloAnnotation
{
@Foo(bar = "Hello World !")
public String str;
public static void main(final String[] args) throws Exception
{
System.out.println(HelloAnnotation.class.getField("str").getAnnotations().length);
}
}
And this is the Annotation:
import java.lang.annotation.ElementType;
import java.lang.annotation.Target;
@Target(ElementType.FIELD)
public @interface Foo
{
public String doTestTarget();
}
My problem is now that getAnnotations() in main is empty. What is wrong with my code?