Does the ArrayList call Clone() on ICloneable objects?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Hasani

    #1

    Does the ArrayList call Clone() on ICloneable objects?

    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.


  • Jon Skeet

    #2
    Re: Does the ArrayList call Clone() on ICloneable objects?

    Hasani <HJB417@hotmail .c0m> wrote:[color=blue]
    > 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?[/color]

    I don't think it'll do either. I think it'll just copy each reference
    from the array into the ArrayList.
    [color=blue]
    > 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.[/color]

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

    --
    Jon Skeet - <skeet@pobox.co m>
    Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

    If replying to the group, please do not mail me too

    Comment

    Working...