黑马程序员技术交流社区
标题:
反射进阶-越过泛型检查
[打印本页]
作者:
游呤人
时间:
2015-7-17 02:00
标题:
反射进阶-越过泛型检查
/*
* 放射的实例,越过泛型检查
* 定义一个泛型为Integer的ArrayList数组,插入一个字符串
* (老子没事做,辛辛苦苦的定了个规则还TMD想越过它......)
*
*
*
*
* */
public class StaticDome {
public static void main(String[] args) throws NoSuchMethodException,
SecurityException, IllegalAccessException,
IllegalArgumentException, InvocationTargetException {
// System.out.println("a");
ArrayList <Integer> list= new ArrayList<Integer>();
//Method addString("add",Object.class);
Method method=list.getClass().getMethod("add", Object.class);
method.invoke(list, "我是字符串 联通");
System.out.println(list.get(0));
}
}
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2