【JAVA:list中再定义一个list对象,循环赋值不同的list数据,出现追加重复数据问题】

问题描述:

list中再定义一个list对象,循环赋值不同的list数据,结果全部都累加到每条数据中了,每条数据中都出现重复数据。

问题解决:

1.创建树结构方法信息

2.创建一个新的 List 对象,避免引用问题

3.使用 GongkuangMethodDictVo 的拷贝构造函数

java 复制代码
public class PlanSchemeProductionGongkuangStatus
{
	。。。。。。
    /** 创建树结构方法信息 */
    private List<GongkuangMethodDictVo> gongkuangMethodDicList;

    public List<GongkuangMethodDictVo> getGongkuangMethodDicList() {
        return gongkuangMethodDicList;
    }

    public void setGongkuangMethodDicList(List<GongkuangMethodDictVo> gongkuangMethodDicList) {
        // 创建一个新的 List 对象,避免引用问题
        this.gongkuangMethodDicList = new ArrayList<>();
        for (GongkuangMethodDictVo gongkuangMethodDictVo : gongkuangMethodDicList) {
            // 使用 GongkuangMethodDictVo 的拷贝构造函数
            this.gongkuangMethodDicList.add(new GongkuangMethodDictVo(gongkuangMethodDictVo));
        }
    }
    。。。。。。
}
相关推荐
美好的事情能不能发生在我身上3 小时前
Hot100中的:贪心专题
java·数据结构·算法
myloveasuka4 小时前
Java与C++多态访问成员变量/方法 对比
java·开发语言·c++
2301_821700534 小时前
C++编译期多态实现
开发语言·c++·算法
Andya_net4 小时前
Spring | @EventListener事件机制深度解析
java·后端·spring
奥地利落榜美术生灬4 小时前
c++ 锁相关(mutex 等)
开发语言·c++
xixihaha13244 小时前
C++与FPGA协同设计
开发语言·c++·算法
lang201509284 小时前
18 Byte Buddy 进阶指南:解锁 `@Pipe` 注解,实现灵活的方法转发
java·byte buddy
重庆小透明4 小时前
【java基础篇】详解BigDecimal
java·开发语言
ID_180079054734 小时前
模拟1688商品详情的Python API实现,返回符合风格的JSON数据
开发语言·python·json
小小怪7505 小时前
C++中的函数式编程
开发语言·c++·算法