package act1;
import java.lang.reflect.Method;
import java.util.ArrayList;
public class Demo {
public static void main (String arg[]) throws Exception{
ArrayList<Integer> al = new ArrayList<Integer>();
Class clazz = ArrayList.class;//获取字节码对象
Method me = clazz.getMethod("add",Object.class);//反射
me.invoke(al, "字符串");
System.out.println(al);
}
}
|
|