Java deepclone an object without some properties -


i have following classes

class {     private long id     private list<b> listb;     private c c;     ... }  class b {     private long id     private a;     private list<d> listd;     ... }  class c {     private long id     private a;     ... }  class d {     private long id     private b b;     ... } 

i need copy of a, include of it's properties except id column.

i have 2 solutions:
1. clone each object , set of ids null;
2. make constructor this:

public (a a){     //copy properties except id     this.xxx = a.xxx;     ... } 

but need write code function, 1 has better method implement function?
lot.

when saying deep cloning of object particularly 1 of type class have instance variable of container type, have below 2 known ways:

1) serialize , deserialize object.

2) traverse through each method , call clone explicitely.

for first implementation, may mark id fields transient , should solve purpose.

for second approach, may override clone method in each class set id field 0/-1) , call super.clone()


Comments

Popular posts from this blog

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

c++ - OpenMP unpredictable overhead -

javascript - Wordpress slider, not displayed 100% width -