Does the ArrayList call Clone() on ICloneable objects?

  • Thread starter Thread starter Hasani
  • Start date Start date
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.
 
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?
 
Back
Top