- public class test01 {
- public static void main(String[] args)throws Exception {
- //建立ArrayList
- ArrayList<Integer> list = new ArrayList<Integer>();
-
- //使用反射方法获取其add方法
- Method addString = list.getClass().getMethod("add",Object.class);
- addString.invoke(list, "string");
- System.out.println(list);
- }
- }
复制代码 |
|