package cn.itcast.Junit;
import java.lang.reflect.Method;
@Myanno1(name = "cn.itcast.Junit.add",Method = "method")//传入指定类名路径和方法名称
public class add1 {
public static void main(String[] args) throws Exception{
Class<add1> add1Class = add1.class;//创建对应的字节码对象 为了获取该注解的里面的name和Method
Myanno1 annotation = add1Class.getAnnotation(Myanno1.class);//传入指定注解的Class文件返回此注解类型的对象
String method = annotation.Method();//获取对象里面的方法
String name = annotation.name();//获取对象里面的包路径
System.out.println(method);//打印输出
System.out.println(name);//打印输出
Class aClass = Class.forName(name);//根据此字符串名称的路径返回此类的Class对象
Method method1 = aClass.getMethod(method);//根据字节码对象调用指定名称的方法
Object o = aClass.newInstance();//创建字节码对应类的对象
Object invoke = method1.invoke(o);//调用实现方法 打印输出此类的方法||对带有指定参数的指定对象调用由此 Method 对象表示的底层方法
}
}