How to make deep copy of java object without using serialization ?

前端 未结 1 1684
温柔的废话
温柔的废话 2021-01-05 14:24

Is it possible to make a deep copy/clone of a Java object without using serialization ? If so then how ?

相关标签:
1条回答
  • 2021-01-05 15:03

    You could use the Java Deep-Cloning Library to make deep copies of objects. It is really useful when you can't (or don't want) to make your classes serializable. The use is straight-forward:

    Cloner cloner = new Cloner();
    
    MyClass clone = cloner.deepClone(o);
    // clone is a deep-clone of o
    
    0 讨论(0)
提交回复
热议问题