我有一個Map
這樣的:如何將對象從一張地圖放到另一張地圖上?
Map<String,GridCell> cellsMap
我通過這個到一個方法,並從方法的返回應包含Map
(比如answerMap
),其中包含的cellsMap
地圖所有條目加上一個額外名額其中包含String
作爲鍵和String
作爲值。例如:
Map<String,Object> answerMap = new ConcurrentHashMap<String,Object>();
//answer should first contain all the map entries of cellsMap and then add an extra entry like the following
answer.put(getId(), getSelectionValue()); // getSelectionValue() returns a String that contains coordinates of the selected cells.
return answerMap;
爲什麼answerMap.putAll()允許我們如果它是危險的?向後兼容原始類型? – Geek 2012-08-09 09:00:57
putAll()不是問題。這是從另一個地圖填充地圖的簡單方法。我的問題是,你使用地圖來存儲不同的無關類型(GridCell和String),所以當你做get()時,你不知道你在得到什麼 – 2012-08-09 09:21:59
是的,我明白你的觀點。 – Geek 2012-08-09 09:39:56