Thread: Cloning
View Single Post
Old 08-03-2003, 12:20 PM   #4 (permalink)
Belisarius
Java fanboy
 
Belisarius's Avatar
 
Join Date: Aug 2003
Posts: 1,174
Belisarius is on a distinguished road
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?
__________________
GitS
Belisarius is offline   Reply With Quote