是否需要MapState.put()手动更新状态,或者修改对象时状态是否自动更新?
private transient MapState<String, Word> words;
.......
Word w = words.get(word);
if (w == null) {
w = new Word(word);
//words.put(word, w); //A
}
if (....) {
w.countBad(1); // countXXX modifies a the private variable in a Word object
} else {
w.countGood(1);
}
//words.put(word, w); //B
Run Code Online (Sandbox Code Playgroud)
Q : 如果我使用A方法,下次计数计算会自动更新相应的Mapstate状态吗?还是需要在计算完成后使用B方法手动更新状态?