用JDK中Annotation写的一个注解
先新建一个Annotation工程
?
?
?
测试package com.lbx.test;import java.lang.reflect.Method;import com.lbx.annotation.NeedTest;import com.lbx.service.ForumService;/** * 测试注解 * @author Administrator * */public class TestAnnotation {public static void main(String[] args) {Class c = ForumService.class; //获得相应的Class对象//先要得到目标对象的Method数组Method[] methods = c.getDeclaredMethods();System.out.println(methods.length);for (int i = 0; i < methods.length; i++) {Method method = methods[i];NeedTest n = method.getAnnotation(NeedTest.class);if(n!=null){if(n.value()){System.out.println(method.getName() + "()需要测试");}else{System.out.println(method.getName() + "()不需要测试");}}}}}?