以后向集合中放東西千萬不要把臨時變量放到for 外面了,請看下面的代碼: 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會是什么樣子? 99, 99, 99, 99, 99~~~~~~~~~~~~ 怎么回事,哎,太不小心了!
誰動了我的集合中的對象?!
只有注冊用戶登錄后才能發表評論。 | ||
![]() |
||
網站導航:
博客園
IT新聞
Chat2DB
C++博客
博問
管理
|
||
相關文章:
|
||