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]
网友评论