|
It's valid only if MyClass implements clone(), as it's not implemented by Object, only defined.
Personally, I think calling a method on the same line as class casting is a bit ambiguous. You probably ought to make y an instance of MyClass as soon as y is defined. For instance, if you get it out of an ArrayList:
MyClass y = (MyClass)list.get(i);
MyClass x = y.clone();
I don't know if that's possible in your situation, but you might want to give it a shot.
I've never heard of the term "shallow clone" before. What is it?
|