package com.sxt.method1;
import java.lang.reflect.Method;
/*
* 需求:通过反射 往泛型Integer的集合里添加String 类型的数据
*/
import java.util.ArrayList;
import java.util.Date;
import java.util.List; public class TestMethod4 {
public static void main(String[] args) throws Exception {
List<Integer> list = new ArrayList<>();
list.add(1);
//获取类信息
Class<? extends List> class1 = list.getClass();
System.out.println(class1);
//获取方法 Object.class
Method method = class1.getDeclaredMethod("add", Object.class);
method.invoke(list, "花花");
method.invoke(list, new Date());
for(Object object: list){
System.out.println(object);
}
System.out.println(list);
}
}