Does the ArrayList call Clone() on ICloneable objects?

H

Hasani

I have an object called FileNode and it implements ICloneable which creates
a deep copy of the FileNode.
The one of the constructors for ArrayList use an ICollection as a paremeter.
If I pass that constructor an array of type FileNode, when it copies the
FileNode array, will it call Clone on each FileNode object, or just do a
MemberwiseClone of each FileNode?

I'm hoping that in the constructor they do somethine like try casting each
object in the ICollection as an ICloneable object and adding it if it's not
null.
 
J

Jon Skeet

Hasani said:
I have an object called FileNode and it implements ICloneable which creates
a deep copy of the FileNode.
The one of the constructors for ArrayList use an ICollection as a paremeter.
If I pass that constructor an array of type FileNode, when it copies the
FileNode array, will it call Clone on each FileNode object, or just do a
MemberwiseClone of each FileNode?

I don't think it'll do either. I think it'll just copy each reference
from the array into the ArrayList.
I'm hoping that in the constructor they do somethine like try casting each
object in the ICollection as an ICloneable object and adding it if it's not
null.

Given the above, why don't you do the clone in your own array?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top