Selection of DGM from multiple options

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Selection of DGM from multiple options

eric.milles

Could someone help me understand the rules for DGMs when multiple methods apply?  I can't seem to find anything in the specification that addresses this and I need to emulate (or call into) the rules for Eclipse.  I also tried walking through MetaClassImpl and MetaMethodIndex, but I got lost in the cache loading code.

 

DefaultGroovyMethods defines these two methods, in this order.  At runtime, if I have an ArrayList, sort(Iterable,Closure) is the method that is called.  Is this because 1) Iterable has wider applicability than Collection, 2) the Collection version is deprecated, 3) the Iterable version is defined last, or 4) something else?

 

    @Deprecated

    public static <T> List<T> sort(Collection<T> self, @ClosureParams(value=FromString.class, options={"T","T,T"}) Closure closure) {

        ...

    }

 

    public static <T> List<T> sort(  Iterable<T> self, @ClosureParams(value=FromString.class, options={"T","T,T"}) Closure closure) {

        ...

    }

 

Eric Milles
Lead Software Engineer

Thomson Reuters

Email: [hidden email]

Phone: 651-848-7040

 

Reply | Threaded
Open this post in threaded view
|

Re: Selection of DGM from multiple options

paulk_asert
Because the method is @Deprecated it won't be seen as a DGM extension method, i.e. when used in the normal Groovy way.

If you call the method long-hand or from Java, both versions will be available. Which reminds me, we were probably going to delete some of those deprecated methods in Groovy 3.

Cheers, Paul.

On Sun, Nov 19, 2017 at 12:39 AM, <[hidden email]> wrote:

Could someone help me understand the rules for DGMs when multiple methods apply?  I can't seem to find anything in the specification that addresses this and I need to emulate (or call into) the rules for Eclipse.  I also tried walking through MetaClassImpl and MetaMethodIndex, but I got lost in the cache loading code.

 

DefaultGroovyMethods defines these two methods, in this order.  At runtime, if I have an ArrayList, sort(Iterable,Closure) is the method that is called.  Is this because 1) Iterable has wider applicability than Collection, 2) the Collection version is deprecated, 3) the Iterable version is defined last, or 4) something else?

 

    @Deprecated

    public static <T> List<T> sort(Collection<T> self, @ClosureParams(value=FromString.class, options={"T","T,T"}) Closure closure) {

        ...

    }

 

    public static <T> List<T> sort(  Iterable<T> self, @ClosureParams(value=FromString.class, options={"T","T,T"}) Closure closure) {

        ...

    }

 

Eric Milles
Lead Software Engineer

Thomson Reuters

Email: [hidden email]

Phone: <a href="tel:(651)%20848-7040" value="+16518487040" target="_blank">651-848-7040