本帖最后由 杜光 于 2013-5-31 07:48 编辑
- import java.util.*;
- class MapDemo4
- {
- public static void main(String[] args)
- {
- HashMap<String,HashMap<String,String>> czbk = new HashMap<String,HashMap<String,String>>();
- HashMap<String,String> yure = new HashMap<String,String>();
- HashMap<String,String> jiuye = new HashMap<String,String>();
- yure.put("01","zhangsan");
- yure.put("02","lisi");
- jiuye.put("01","wangwu");
- jiuye.put("02","zhaoliu");
- czbk.put("01",yure);
- czbk.put("02",jiuye);
-
- Iterator<String> it = czbk.keySet().iterator();
- while(it.hasNext())
- {
- String roomname = it.next();
- HashMap<String,String> room = czbk.get(roomname);
- getInof(roomname);
- }
- }
- public static void getInof(HashMap<String,String> T)
- {
- Iterator<String> it = T.keySet().iterator();
- while(it.hasNext())
- {
- String id = it.next();
- String name = T.get(id);
- System.out.println(id+"..."+name);
- }
- }
- }
复制代码 MapDemo4.java:27: 错误: 无法将类 MapDemo4中的方法 getInof应用到给定类型;
getInof(roomname);
^
需要: HashMap<String,String>
找到: String
原因: 无法通过方法调用转换将实际参数String转换为HashMap<String,String>
编译报错,不是很明白,为什么非要
HashMap<String,String> room = czbk.get(roomname);
getInof(room);
这样调用才行呢?
System.out.println(roomname); 和 getInof(yure);应该传的参数是一样的啊!不解
|