jastrachan | 18 Nov 11:39 2004
Picon

Re: Feedack on Groovy


On 18 Nov 2004, at 08:35, Laforge Guillaume wrote:

>
>> I'd like to add a mechanisms for types to be able to decide how they
>> coerce to other types; though I'd assume a cast (or the 'as' operator)
>> would be used to do the coercsion. e.g.
>>
>> List l = someArray as List
>
> Since it's not really a cast, but a type morphing into another type, 
> that makes a lot of sense to use a different mechanism, at least 
> syntactically.
> So, List l = someArray as List looks pretty good.
> I guess users will have the possibility of creating their own mutation 
> routines.
> How could we do that? Something like the DefaultGroovyMethods?

By logically providing some kinda coercion method.

e.g. something logically like

class Cheese {
     Object asType(Class type) {
	switch (type) {
	    case List:
		return asList()
	    }
	return null
     }
}

James
-------
http://radio.weblogs.com/0112098/


Gmane