jastrachan | 31 Mar 10:36 2005

Re: Re: [groovy-dev] RE: Some enhanced methods for collection

On 31 Mar 2005, at 09:30, Dierk Koenig wrote:
> I'm a bit puzzled be the word "coercion" here.
> Would you agree to the following definition?
> "coercion" changes the dynamic type of an object
> without changing its identity.

No. You can never change the type of something, you can only create a 
new object of a different type, with a different identity.

> "conversion" changes (static?) type and identity.
> Are the asXXX methods "coercion" methods in this sense
> while toXXX methods are "conversion" methods?

I think the toXXX create a separate copy of the object; the asXXX try 
and keep the original backed object. e.g. Arrays.asList(array) will 
create a List backed by the original array, changing the list will 
change the array contents. List.toArray() will create a new list which 
modifications are not backed into the list.