以后向集合中放東西千萬不要把臨時(shí)變量放到for 外面了,請(qǐng)看下面的代碼: List resultList=new ArrayList(); Model model =new Model(); for (int i = 0; i < 100; i++) { String str=i+""; model.setAttr(str); resultList.add(model); } return resultList; 大家猜以下返回的resultList會(huì)是什么樣子? 99, 99, 99, 99, 99~~~~~~~~~~~~ 怎么回事,哎,太不小心了!
誰動(dòng)了我的集合中的對(duì)象?!
只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。 | ||
![]() |
||
網(wǎng)站導(dǎo)航:
博客園
IT新聞
Chat2DB
C++博客
博問
管理
|
||
相關(guān)文章:
|
||