1.自定义的annotation
package com.qimh.annotion;import java.lang.annotation.Retention;import java.lang.annotation.RetentionPolicy;@Retention(RetentionPolicy.RUNTIME)public @interface MyAnnotation { String key(); String value();}
2.测试自定义的MyAnnotation
package com.qimh.annotion;@MyAnnotation(key="11",value="22")public class TestAnnotion { public static void main(String[] args) {// TestAnnotion testAnnotion = new TestAnnotion();// System.out.println(TestAnnotion.class); MyAnnotation myAnnotation = TestAnnotion.class.getAnnotation(MyAnnotation.class); System.out.println("key="+myAnnotation.key()+",value="+myAnnotation.value()); }}
参考链接: