//用反射做
public static void main(String[] args) throws Exception {
ArrayList<Integer> list = new ArrayList<>();
list.add(1234);
list.add(2222);
Class clazz = Class.forName("java.util.ArrayList");
Method method = clazz.getMethod("add", Object.class);
method.invoke(list, "插入了");
System.out.println(list);
}
}
|
|