What I would like to do is to define a copy constructor which
takes A as an argument and it initializes the new A to be a deep
copy of argument A
public class A<E extends Comparable<? super E>> implements B<E>
{
private A a;
private E[] hArray;
// What I tried .... my copy constructor
public A(A other)
{
this.a = other; // deep copy
}
}
Is this the right way of doing deep copy through copy constructor??
That’s not a deep copy. You are just storing the reference to the other object.
Try this:
This assumes that E also has a copy constructor that performs a deep copy. Plus I just noticed that E is a generic, so my code might not work correctly for that (but the idea is there).