-2
我無法用一個類型CAS的錯誤,我不能找出爲什麼它不斷坡平鑄造的HashMap
錯誤消息:[Ljava.lang.Object; cannot be cast to [Lnet.masterthought.cucumber.json.Stuff;
它在線上彈出this.stuffs = (Stuff[]) sList.toArray();
任何人都有什麼想法是什麼問題?
public class Element {
private Stuff[] stuff;
//... getters setters
public function updateStuff(Stuff[] newStuff) {
Map<String, Stuff> stuffMap = new HashMap<String, Stuff>();
for (Stuff s : this.stuffs) {
stuffMap.put(s.getName(), s);
}
for (Stuff s : prevStuffs) {
if (stuffMap.containsKey(s.getName())) {
stuffMap.get(s.getName()).setValue(s.getValue());
}
}
ArrayList<Stuff> sList = new ArrayList<Stuff>(stuffMap.values());
this.stuffs = (Stuff[]) sList.toArray();
}
}
或更簡單:'sList.toArray(new Stuff [0]);' – assylias 2015-03-31 21:33:35
@assylias謝謝你。我不知道你可以這樣做。 'toArray' API是一條全狗早餐。 – 2015-03-31 21:41:04