- package cn.conpany.test;
- import java.lang.reflect.InvocationTargetException;
- import java.util.ArrayList;
- import java.util.Collection;
- public class RefectColl {
- public static void main(String[] args) throws Exception {
- ArrayList<Integer> list = new ArrayList<Integer>();
- list.add(0);
- list.getClass().getMethod("add", Object.class).invoke(list, "ssss");
- System.out.println("list:" + list.get(0));
- System.out.println("list:" + list.get(1));
- System.out.println("list:" + list.getClass().getMethod("get", int.class).invoke(list, 0));
- System.out.println("list:" + list.get(1).getClass().getName());
-
- }
- }
-
-
复制代码 再给你一个有趣的程序,你可以试着运行,每次异常出现的结果和打印的结果都会换位置,如图:
|