[ https://issues.apache.org/jira/browse/GROOVY-6992?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Eric Milles closed GROOVY-6992. ------------------------------- Resolution: Fixed As of Groovy 4, the {{collect}} variants that accept a collector propagate the collector's type. For example: {code:groovy} @groovy.transform.TypeChecked void test() { def one_two_three = [1,2,3] @groovy.transform.ASTTest({ println node.getNodeMetaData(org.codehaus.groovy.transform.stc.StaticTypesMarker.INFERRED_TYPE) }) def two_times = one_two_three.collect(new HashSet<Number>()) { it * 2 } } test() {code} This script prints "java.util.HashSet<java.lang.Number>" for the inferred type of {{two_times}}. This lets you control the type and carry on with that type instead of having to cast from {{Collection}} as before. > Support collect on sets > ----------------------- > > Key: GROOVY-6992 > URL: https://issues.apache.org/jira/browse/GROOVY-6992 > Project: Groovy > Issue Type: Improvement > Affects Versions: 2.3.6 > Reporter: Mark Perry > Priority: Major > > At the moment, calling collect on sets returns a list. You can pass in a set > as a collection to add to, but then the return type is collection, which is > not what you want. -- This message was sent by Atlassian Jira (v8.20.10#820010)