- package wjd.write;
- import java.lang.reflect.Method;
- import java.util.ArrayList;
- //ArrayList list = new ArrayList(); 在这个泛型为Integer的ArrayList中存放一个String类型的对象
- public class Test06 {
- public static void main(String[] args) throws Exception {
- ArrayList<Integer> list = new ArrayList<Integer>();
- Method addMethod = list.getClass().getMethod("add", Object.class);
- addMethod.invoke(list, "wjd");
- System.out.println(list);
- }
- }
复制代码 |