[ https://issues.apache.org/jira/browse/GROOVY-10074?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17340915#comment-17340915 ]
Eric Milles commented on GROOVY-10074: -------------------------------------- Suggestion from the mailing list of using Java's functional interfaces, like {{Function}}, instead of {{Closure}} would be another way to go here. > DGM: Fix transform generics for collect and similar > --------------------------------------------------- > > Key: GROOVY-10074 > URL: https://issues.apache.org/jira/browse/GROOVY-10074 > Project: Groovy > Issue Type: Improvement > Components: groovy-jdk > Reporter: Eric Milles > Priority: Minor > > The {{collect}} DGM is defined like this for {{Iterable}}, arrays, etc.: > {code:java} > <T> List<T> collect(Object self, Closure<T> transform) > <S,T> List<T> collect(S[] self, @ClosureParams(FirstParam.Component.class) > Closure<T> transform) > <S,T> List<T> collect(Iterable<S> self, > @ClosureParams(FirstParam.FirstGenericType.class) Closure<T> transform) > <S,T> List<T> collect(Iterator<S> self, > @ClosureParams(FirstParam.FirstGenericType.class) Closure<T> transform) > {code} > and like this for the variants that accept an output collection: > {code:java} > <T> Collection<T> collect(Object self, Collection<T> collector, Closure<? > extends T> transform) > ... > {code} > I think {{Closure<? extends T>}} is better. It would allow plain {{collect}} > to work for this example under STC without requiring {{? extends > CharSequence}} on the target or a typecast for "it" or the call expression: > {code:groovy} > List<CharSequence> list = ['string'].collect { it } > {code} > For comparison, Java's {{Stream#map}} function is defined this way: > {code:java} > <R> Stream<R> map(Function<? super T, ? extends R> mapper) > {code} -- This message was sent by Atlassian Jira (v8.3.4#803005)