You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@groovy.apache.org by er...@thomsonreuters.com on 2017/11/18 14:39:38 UTC

Selection of DGM from multiple options

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: eric.milles@thomsonreuters.com
Phone: 651-848-7040


Re: Selection of DGM from multiple options

Posted by Paul King <pa...@asert.com.au>.
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, <er...@thomsonreuters.com> 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: eric.milles@thomsonreuters.com
>
> Phone: 651-848-7040 <(651)%20848-7040>
>
>
>