ArrayList<String> collection1 = new ArrayList<String>();
collection1.add("abc");
collection1.add("def");
Method add1 = collection1.getClass().getMethod("add", Object.class);
add1.invoke(collection1, 1);
System.out.println(collection1.get(2));
为什么这么写会报异常,不能够自动装箱吗?
|