通过反射的方式拿到collection接口的add(object)方法
- public class Test3 {
- public static void main(String[] args)throws Exception {
- ArrayList<Integer> list = new ArrayList<Integer>();
-
- Method m = list.getClass().getMethod("add", Object.class);
- m.invoke(list, "String");
-
- System.out.println(list.get(0));
- }
- }
复制代码 |