泛型擦除
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.ArrayList; public class Demo04 { public static void main(String[] args) throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { // 泛型擦除 ArrayList<String> rr=new ArrayList<String>(); rr.add("张倩"); // 获取字节码 Class c=rr.getClass(); //获取方法 Method m=c.getMethod("add", Object.class); //调用方法 m.invoke("rr",123 ); //遍历 for(Object obj:rr){ System.out.println(obj); } } }