I try to get my head straight about cloning in Java with my own ArrayList.
For what I see this code
@Override
public Object clone() {
try {
MyArrayList<E> v = (MyArrayList<E>) super.clone();
v.elementData = Arrays.copyOf(elementData, size);
return v;
} catch (CloneNotSupportedException e) {
throw new InternalError();
}
}
Gives the same result as
@Override
public Object clone() {
try {
return (MyArrayList<E>) super.clone();
} catch (CloneNotSupportedException e) {
throw new InternalError();
}
}
Am I doing something wrong or why use the Arrays.copyOf()?
elementDatain relation toMyArrayList? Are you trying to do a "deep copy" ?