Package package3;
Import Java.lang.annotation.ElementType;
Import java.lang.annotation.Retention;
Import Java.lang.annotation.RetentionPolicy;
Import Java.lang.annotation.Target;
Annotated annotations
@Retention (Retentionpolicy.runtime)
Represents the scope of the annotation trial, where it is used only on the variable
@Target (Elementtype.field)
Public @interface Myannotation {
String value () default ""; Properties of annotations
}
Package package3;
Import Java.lang.reflect.Field;
public class MyTest {
@MyAnnotation ("Zhangsna")
String s;
public static void Main (string[] args) throws SecurityException, Nosuchfieldexception {
Class clazz = Mytest.class;
Field fl = Clazz.getdeclaredfield ("s");
Get annotations for attributes
Myannotation mn = Fl.getannotation (Myannotation.class);
System.out.println (Mn.value ());//properties that get annotations
}
}
Learning about Java annotations