import java.lang.reflect.Method;
import java.util.ArrayList;
public class Test1 {
/**
* @param args
* @throws NoSuchMethodException
* @throws SecurityException
*/
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
ArrayList<Integer> al = new ArrayList<Integer>();
al.add(11);
al.add(22);
al.add(33);
Method m = al.getClass().getMethod("add", Object.class);
m.invoke(al, "hello world1");
m.invoke(al, "hello world2");
m.invoke(al, "hello world3");
System.out.println(al.toString());
}
}
定义了泛型的集合中也可以加入其它类型的数据
最新推荐文章于 2023-12-16 00:56:32 发布