- public static void main(String[] args) throws Exception{
- ArrayList<Integer> list = new ArrayList<Integer>();//创建List对象
- Class clazz = list.getClass();//获取list字节码对象
- Method add = clazz.getMethod("add", Object.class);//获取add方法
- add.invoke(list, "我来了");//使用add方法
- System.out.println(list);//打印集合
- }
复制代码
|
|