日期:2014-05-20  浏览次数:20718 次

为什么不能直接new HashMap<key, value>().put(key, value)???
Java code

Map<Long, Double> map = new HashMap<Long, Double>().put(11L, 22D);//compile error

Map<Long, Double> map = new HashMap<Long, Double>();
map.put(11L, 22D);//correct


提示:
Type mismatch: cannot convert from Double to Map<Long,Double>
怎么识别成Double去了

------解决方案--------------------
探讨
Java code

Map<Long, Double> map = new HashMap<Long, Double>().put(11L, 22D);//compile error

Map<Long, Double> map = new HashMap<Long, Double>();
map.put(11L, 22D);//correct


提示:
Type mismatch: c……