@Retention(value=RetentionPolicy.RUNTIME)
public @interface MyTest {
}
public class AnnotationDemo1 {
@MyTest
public void demo1(){
System.out.println("方法1...");
}
@MyTest
public void demo2(){
System.out.println("方法2...");
}
@Test
public void demo3(){
System.out.println("方法3...");
}
public class DemoRunner {
public static void main(String[] args) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException {
//获得测试类的class
Class clazz=AnnotationDemo1.class;
//获得class中的所有的方法
Method[] mothods=clazz.getMethods();
//遍历每个方法,
for(Method method:mothods){
boolean flag = method.isAnnotationPresent(MyTest.class);
System.out.println(flag);
if(flag){
// 说明方法上有MyTest注解:
method.invoke(clazz.newInstance(), null);
}
}
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有