List内对象的值无故发生变化
list内有对象若干 中间因为要查询其他数据所以用了一下 没有remove 没有add操作 list内对象的值莫名其妙的发生了变化 变化的情况:假设里面有5个对象 5个对象的name分别是 A B C D E 变化以后变成了类似 A A B B D这样的情况
试着将list内的值复制给了一个临时的List 问题依旧
List<Project> sectorslist = projectService.findProjectListGroupBySectors(projectname);
List<Project> myList = new ArrayList<Project>();
for(int i=0;i<sectorslist.size();i++){
myList.add(sectorslist.get(i));
}
//以上是对sectorslist 的复制 打印sectorslist 和myList结果类似 A B C D E
Project tempProject = null;
Project pall = null;
Project pcan = null;
Sectors tempSectors = null;
for(int i=0;i<lensnoList.size();i++){
pcan = lensnoList.get(i);
for(int j=projectlist.size()-1;j>=0;j--){
pall = projectlist.get(j);
if(pall.getLensno().equals(pcan.getLensno())){
if(pall.getSectorstatus().equals("PASS")){
for(int k=0;k<myList.size();k++){
if(pall.getSectors().getId().equals(myList.get(k).getSectors().getId())&&k<myList.size()-1){
tempProject = myList.get(k+1);
tempProject.setSectors(pall.getSectors());
break;
}
}
}
else{
if(!pall.getSectorstatus().equals("NOGIVE")){
for(int k=0;k<myList.size();k++){
if(pall.getSectors().getId().equals(myList.get(k).getSectors().getId())){
if(k>0){
tempProject = myList.get(k-1);
tempProject.setSectors(pall.getSectors());
}
if(k==0){
tempProject = pall;
tempSectors = tempProject.getSectors();
tempSectors.setId(-1);
tempProject.setSectors(tempSectors);
}
break;
}
}
}
else{
if(pall.getSectorstatus().equals("MAKING")){
for(int k=0;k<myList.size();k++){
if(pall.getSectors().getId().equals(myList.get(k).getSectors().getId())){
if(k>0){
tempProject = myList.get(k-1);
tempProject.setSectors(pall.getSectors());
}
if(k==0){
tempProject = pall;
tempSectors = tempProject.getSectors();
tempSectors.setId(-1);
tempProject.setSectors(tempSectors);
}
}
}
}
}
}
}
pall = null;
tempProject = null;
tempSectors = null;
}
needLensList.add(tempProject);
pcan = null;
//经过上面这一段代码之后 myList sectorslist 的值都发生了变化 类似A A A B B
第一次遇到这样的情况 找了好久 . 都快崩溃了 求高人帮帮忙