public class ArrayListDemo {
public static void main(String[] args) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
List<Integer> list = new ArrayList<Integer>();
list.add(1);
// list.add("hello");不能添加
Class clzz = list.getClass();
Method method = clzz.getMethod("add",Object.class);
method.invoke(list,"hello");
System.out.println(list);
}
}
评论区