Java custom annotation Interpretation
Package annotation; import java. lang. annotation. retention; import java. lang. annotation. retentionPolicy; // RUNTIME indicates that the Person annotation also exists at RUNTIME // @ Retention (RetentionPolicy. CLASS) @ Retention (RetentionPolicy. RUNTIME) @ interface Person {String name (); int age () ;}@ Person (name = Tom, age = 20) class Test1 {}@ Person (name = Jack, age = 22) class Test2 {}// @ Person (name = Anna, age = 18) class Test3 {}public class AnnotationTest {public static void PrintClassInto (Class c) {System. out. print (c. getName () +.); Person person = (Person) c. getAnnotation (Person. class); if (person! = Null) {System. out. println (Person: + person. name () +, age: + person. age ();} else {System. out. println (unknown person) ;}} public static void main (String [] args) {printClassInto (Test1.class); printClassInto (Test2.class); printClassInto (Test3.class );}}