美文网首页Java
Groovy deep clone Map

Groovy deep clone Map

作者: JaedenKil | 来源:发表于2021-09-29 14:54 被阅读0次
    class MapCloneDemo003 {
        static void main(String[] args) {
            Map map1 = [
                    simpleType : 123,
                    complexType : [a : 1, b : 2],
                    boolType : true,
            ]
    
            ByteArrayOutputStream bos = new ByteArrayOutputStream()
            ObjectOutputStream oos = new ObjectOutputStream(bos)
            oos.writeObject(map1)
            oos.flush()
            oos.close()
            ByteArrayInputStream bin = new ByteArrayInputStream(bos.toByteArray())
            ObjectInputStream ois = new ObjectInputStream(bin)
            Map map2 = (Map) ois.readObject()
            ois.close()
            bos.flush()
            bos.close()
            map2.get("complexType").put('c', 13)
            map2.get("complexType").put('d', 14)
    
            println(map1)
            println(map2)
        }
    }
    
    [simpleType:123, complexType:[a:1, b:2], boolType:true]
    [simpleType:123, complexType:[a:1, b:2, c:13, d:14], boolType:true]
    

    相关文章

      网友评论

        本文标题:Groovy deep clone Map

        本文链接:https://www.haomeiwen.com/subject/gbsjnltx.html