【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));
        }
    }
    。。。。。。
}
相关推荐
A.A呐4 分钟前
【C++第二十九章】IO流
开发语言·c++
椰猫子8 分钟前
Java:异常(exception)
java·开发语言
lifewange11 分钟前
pytest-类中测试方法、多文件批量执行
开发语言·python·pytest
cmpxr_35 分钟前
【C】原码和补码以及环形坐标取模算法
c语言·开发语言·算法
2401_827499991 小时前
python项目实战09-AI智能伴侣(ai_partner_5-6)
开发语言·python
PD我是你的真爱粉1 小时前
MCP 协议详解:从架构、工作流到 Python 技术栈落地
开发语言·python·架构
win x1 小时前
Redis 使用~如何在Java中连接使用redis
java·数据库·redis
星晨雪海1 小时前
基于 @Resource 的支付 Service 多实现类完整示例
java·开发语言
阿维的博客日记1 小时前
什么是逃逸分析
java·juc
ACP广源盛139246256732 小时前
破局 Type‑C 切换器痛点@ACP#GSV6155+LH3828/GSV2221+LH3828 黄金方案
c语言·开发语言·网络·人工智能·嵌入式硬件·计算机外设·电脑