Eric Milles created GROOVY-10074: ------------------------------------ Summary: DGM: Fix transform generics for collect and similar Key: GROOVY-10074 URL: https://issues.apache.org/jira/browse/GROOVY-10074 Project: Groovy Issue Type: Bug Components: groovy-jdk Reporter: Eric Milles
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)