I'm using a class (let's call it the BaseClass) from a package which implements the Cloneable interface, but it appears to do so by creating a new object and not by calling super.clone(). I have made a SubClass of this BaseClass, which then crashes when I attempt to clone it. In code, I have something like this:
// from library
class BaseClass implements Cloneable{
public void clone(){
BaseClass clone = new BaseClass(); // I guess?
...
return clone;
}
}
// my subclass
class SubClass extends BaseClass{
public void clone() throws CloneNotSupportedException {
return (SubClass) super.clone(); // throws ClassCastException
}
}
One way would be to skip the extends BaseClass and just use a pointer, though it would really complicate my code.
What are my options if I really need to be able to make copies (one way or another)?
Thanks