日期:2014-05-19  浏览次数:20676 次

请教关于泛型类型的转换问题?
我在网上打了一个别的写的程序,想学一下是怎么样实现的?我就用jd-gui把它给反编译了。其中有这样一个方法
Java code

  public static void langEditorInit(HttpServletRequest request, HttpServletResponse response) throws Exception
  {
    StringBuilder tabs = new StringBuilder(); 
    StringBuilder tree = new StringBuilder();
    ConcurrentHashMap lans = 
      Str.getLangMap();
    List ls = StringUtil.sortMapKey(lans);

    boolean isFirst = true;

    for (Map.Entry e : ls) {
      String key = (String)e.getKey();
      ConcurrentHashMap v = (ConcurrentHashMap)lans.get(key);
      if (v.size() != 0) {
        if (isFirst) {
          isFirst = false;
        } else {
          tabs.append(',');
          tree.append(',');
        }
        tabs.append("{title:");
        tabs.append(StringUtil.quote(key));
        tabs
          .append(
          StringUtil.concat(
          ",id:\"tab_", new String[] { 
          key, 
          "\",layout:\"fit\",items:[{xtype:\"textarea\",id:\"area_", 
          key, "\"}]" }));
        tabs.append('}');
        tree.append("{text:");
        tree.append(StringUtil.quote(key));
        tree.append(",iconCls:\"item_icon\",leaf:true");
        tree.append('}');
      }
    }
    request.setAttribute("langTabs", tabs.toString());
    request.setAttribute("treeContent", tree.toString());
  }



public static List<Entry<String, ?>> sortMapKey(Map<String, ?> map) {
        return sortMapKey(map, false);
    }

    public static List<Entry<String, ?>> sortMapKey(Map<String, ?> map,
            boolean keyAsNumber) {
        List<Entry<String, ?>> list = new ArrayList<Entry<String, ?>>(map
                .entrySet());
        final boolean keyAsNum = keyAsNumber;
        Collections.sort(list, new Comparator<Entry<String, ?>>() {
            Collator collator = Collator.getInstance();

            public int compare(Entry<String, ?> e1, Entry<String, ?> e2) {
                if (keyAsNum)
                    return Integer.parseInt(e1.getKey())
                            - Integer.parseInt(e2.getKey());
                else {
                    CollationKey key1 = collator.getCollationKey(e1.getKey()
                            .toLowerCase());
                    CollationKey key2 = collator.getCollationKey(e2.getKey()
                            .toLowerCase());
                    return key1.compareTo(key2);
                }
            }
        });
        return list;
    }



我把它放到myeclip中时,for (Map.Entry e : ls) 这句提示"Map cannot be resolved to a type",这是什么原因啊?
我觉得应该是这里不对吧List ls = StringUtil.sortMapKey(lans);,不应该用List ls接收吧?
如果改成这样List<Entry<String, ?>> ls = StringUtil.sortMapKey(lans); ,提示是数据不匹配,有谁知道该怎么定义?谢谢!

------解决方案--------------------
你查一下 import,
有没有

import java.util.Map;
import java.util.Map.Entry;
------解决方案--------------------
类型不匹配,首先看看 包有没有导入 map 应该是值或者KEY 才可以用LIST接收
------解决方案--------------------
Map.Entry这个是包访问权限吧??你怎么调用啊???