jastrachan | 7 Apr 11:33 2004

Re: [IDEA] auto-type coercion thoughts

On 7 Apr 2004, at 10:09, bing ran wrote:

> How about conversion constructors on the target object types:
> class Target {
>      Target(SourceType1 src) {
>      }
>     Target(SourceType2 src) {
>      }
> }
> Target t = new SourceType1()  =>  Target t = new Target(new
> SourceType1())
> Target t = new SourceType2()  =>  Target t = new Target(new
> SourceType2())
> perhaps too much implicity...
> I think it might be a good idea to refactor the DefaultGroovyMethod
> class, which has become too bulky.


> I don't understand why we cannot
> create subclasses for those most used java classes such as String, 
> List,
> File etc..  so we will have GString (already there, but in different
> flavor), GFile, GCollection etc and all the relevant convenient methods
> currently defined in the DefaultGroovyMethods can spread out to the
> right places.

We can't extend things like String, Integer, Object[] since they are 
final in the JDK - so we have to 'mixin' new methods to existing JDK 
classes rather than use derivation. Its essential that we make normal 
Java objects like String, Object[] as well as any Collection, List, Map 
implementations more groovy. I don't want us to have to create Groovy 
derivations of the entire JDK :)