package myanno;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface MyAutoValue {
public String value() default "";
}
package myanno;
import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
public class Test {
@MyAutoValue("hello world")
public static String value;
public static void main(String args[]) throws ClassNotFoundException, NoSuchFieldException, SecurityException{
Class clazz = Class.forName("myanno.Test");
Field field = clazz.getField("value");
Annotation[] ans = field.getAnnotations();
System.out.println(((MyAutoValue) ans[0]).value());
}
}