package com.itheima_13; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.ArrayList; public class ReflectTest01 { public static void main(String[] args) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException { ArrayList<Integer> array=new ArrayList<Integer>(); Class<? extends ArrayList> c = array.getClass(); Method m = c.getMethod("add", Object.class); m.invoke(array,"hello"); m.invoke(array,"world"); m.invoke(array,"java"); System.out.println(array); } }
08-09
2758
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)