In which cases should I use this way:
public A clone() throws CloneNotSupportedException {
A clone = (A)super.clone();
clone.x= this.x;
return clone;
}
And in which cases should I use that way:
public ShiftedStack clone() throws CloneNotSupportedException {
return new A(this.x);
}
What should I do if x
is final and I want to use the first way?
Regarding the first way, I understand it like this: we clone the super class and up-cast it, leading to some members uninitialized. After this initialize these members. Is my understanding correct?
Thank you.