I got the following Questions on my code:
public class Parent {
...
}
public class Child extends Parent implements Cloneable {
...
@Override
public Child clone() {
return new Child() //deep copy
}
}
Here are my questions:
- Following the java conventions; Do i need to implement Cloneable for the parent as well?
- Do i have to add
throws CloneNotSupportedException
to the clone() method or am i allowed to leave it byside? Cause i cant catch the Exception where i call clone().
Thanks for your help.
Edit: I went with copy constructors, cause they are much more easier to implement and dynamic.