import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
public class CollectionDemo {
public static void main(String[] args) throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
List list = new ArrayList();
list.add(11);
list.add(22);
list.add(33);
//list.add("哈哈");
System.out.println(list);
//-----------------------------------------
//通过反射跨过泛型
Class c = List.class;//类名.class
//public abstract boolean add(E e)
//找add方法
Method addReflect = c.getMethod("add", Object.class);
//调用add方法
//list.add("呵呵");
Object flag = addReflect.invoke(list, "呵呵");
System.out.println("flag:"+flag);
System.out.println(list);
}
}