You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@mahout.apache.org by Dan Filimon <da...@gmail.com> on 2013/01/02 22:50:37 UTC

DelegatingVector's clone()

I'm confused what DelegatingVector's clone() method is trying to do.
I'm playing with it to create the DecoratedVector<T> type.

Here it is [1].
So, it first calls its super class, super.clone() at line 5 (which is
in fact Object's clone() since this class doesn't extend anything).
Then, it clones the delegate vector, delegate.clone() at line 10.

Why is it doing this? Isn't calling super.clone() enough? It's only
doing member copying, right?
Cloning the delegate vector is something Object.clone() did anyway, isn't it?

[1] https://gist.github.com/4438413

Re: DelegatingVector's clone()

Posted by Dan Filimon <da...@gmail.com>.
Yes, that makes sense. Thanks! :)

On Wed, Jan 2, 2013 at 11:57 PM, Julien Aymé <ju...@gmail.com> wrote:
> Object.clone() only clones the references to the member fields.
> It does not a "deep" clone. It is the responsibility of subclasses
> which want to do so to copy the desired member fields (in general only
> mutable fields are cloned, the immutable ones are left).
>
> Hope this helps,
> Regards,
> Julien
>
> 2013/1/2 Dan Filimon <da...@gmail.com>:
>> I'm confused what DelegatingVector's clone() method is trying to do.
>> I'm playing with it to create the DecoratedVector<T> type.
>>
>> Here it is [1].
>> So, it first calls its super class, super.clone() at line 5 (which is
>> in fact Object's clone() since this class doesn't extend anything).
>> Then, it clones the delegate vector, delegate.clone() at line 10.
>>
>> Why is it doing this? Isn't calling super.clone() enough? It's only
>> doing member copying, right?
>> Cloning the delegate vector is something Object.clone() did anyway, isn't it?
>>
>> [1] https://gist.github.com/4438413

Re: DelegatingVector's clone()

Posted by Julien Aymé <ju...@gmail.com>.
Object.clone() only clones the references to the member fields.
It does not a "deep" clone. It is the responsibility of subclasses
which want to do so to copy the desired member fields (in general only
mutable fields are cloned, the immutable ones are left).

Hope this helps,
Regards,
Julien

2013/1/2 Dan Filimon <da...@gmail.com>:
> I'm confused what DelegatingVector's clone() method is trying to do.
> I'm playing with it to create the DecoratedVector<T> type.
>
> Here it is [1].
> So, it first calls its super class, super.clone() at line 5 (which is
> in fact Object's clone() since this class doesn't extend anything).
> Then, it clones the delegate vector, delegate.clone() at line 10.
>
> Why is it doing this? Isn't calling super.clone() enough? It's only
> doing member copying, right?
> Cloning the delegate vector is something Object.clone() did anyway, isn't it?
>
> [1] https://gist.github.com/4438413

Re: DelegatingVector's clone()

Posted by Sean Owen <sr...@gmail.com>.
Object.clone() does a shallow copy. The clone has a copy of the
reference inside the object, but the referent is not cloned unless you
do so directly.

On Wed, Jan 2, 2013 at 9:50 PM, Dan Filimon <da...@gmail.com> wrote:
> I'm confused what DelegatingVector's clone() method is trying to do.
> I'm playing with it to create the DecoratedVector<T> type.
>
> Here it is [1].
> So, it first calls its super class, super.clone() at line 5 (which is
> in fact Object's clone() since this class doesn't extend anything).
> Then, it clones the delegate vector, delegate.clone() at line 10.
>
> Why is it doing this? Isn't calling super.clone() enough? It's only
> doing member copying, right?
> Cloning the delegate vector is something Object.clone() did anyway, isn't it?
>
> [1] https://gist.github.com/4438413