黑马程序员技术交流社区
标题:
Integer泛型Map中存储字符串(反射)
[打印本页]
作者:
zhanghongtuo
时间:
2016-5-31 16:41
标题:
Integer泛型Map中存储字符串(反射)
HashMap<Integer, String> hm = new HashMap<Integer, String>();
hm.put(1,"张三");
hm.put(2,"李四");
hm.put(3,"王五");
Class clazz = Class.forName("java.util.HashMap");
Method m =clazz.getMethod("put",Integer.class,String.class); 报错,求指导
m.invoke(hm, "aaa","bbb");
System.out.println(hm);
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2