Using lombok, I am interested to copy all the fields from a base class instance to the derived class via its constructor, very similar to what C++ copy constructor does. Presently concern is not so much on whether the copy is deep or shallow. I have a base class as shown below,
class Parent {
.... fields
}
and I am interested to automatically generate a derived class constructor which takes base class instance and copy (either shallow or deep) all the fields to the derived one. e.g.
class Child extends Parent {
... derived fields
Child(Parent p) { // can be implemented as super(p);
}
}
I have the flexibility to annotate both Parent and Child class as needed, however do not want to handcraft the constructor, which copies each fields one by one. Example usage
Parent parent = Parent.of(....);
Child child = new Child(parent);