- package Test69;
- import java.lang.reflect.Method;
- import java.util.Map;
- import java.util.TreeMap;
- /**
- * Integer泛型Map中存储字符串
- * @author BUN
- *
- */
- public class MapDemo {
- public static void main(String[] args) {
- Map<Integer, Integer> map = new TreeMap<Integer, Integer>();
- map.put(1, 100);
- map.put(2, 200);
- map.put(3, 300);
- System.out.println(map);
- method(map);
- System.out.println(map);
- }
- private static void method(Map<Integer, Integer> map) {
- Class c = map.getClass();
- try{
- Method m = c.getMethod("put",Object.class,Object.class);
- m.invoke(map,"a","b");
- }catch(Exception e){
- e.printStackTrace();
- }
- }
- }
复制代码 |
|