java list深拷贝

可以通过将list转成json,在把json转成list即可

 List<SysUser> a = Lists.newArrayList();
        SysUser u1 =new SysUser();
        u1.setUserId(1L);
        a.add(u1);
        List<SysUser> b = JSONUtil.toBean(JSONUtil.toJsonStr(a), new TypeReference<List<SysUser>>() {
        }, true);
        System.err.println(a);//com.dongqiimi.common.core.domain.entity.SysUser@4fb64261
        System.err.println(b);//com.dongqiimi.common.core.domain.entity.SysUser@401e7803
System.err.println(a);//com.dongqiimi.common.core.domain.entity.SysUser@4fb64261
System.err.println(b);//com.dongqiimi.common.core.domain.entity.SysUser@401e7803
posted @ 2024-01-02 10:39  Sea_wxx  阅读(152)  评论(0编辑  收藏  举报