[ https://issues.apache.org/jira/browse/GROOVY-7774?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15193509#comment-15193509 ]
Shil Sinha edited comment on GROOVY-7774 at 3/14/16 3:46 PM: ------------------------------------------------------------- The compiler determines the target method for {{set.addAll(toAdd)}} to be {{DefaultGroovyMethods#addAll(Collection<T>, Iterable<T>)}} rather than {{Collection<E>#addAll(Collection<? extends E>)}}, resulting in the error you described due to the lack of wildcard on the iterable parameter to the DGM addAll method. was (Author: shils): The compiler determines the target method for `set.addAll(toAdd)` to be `DefaultGroovyMethods#addAll(Collection<T>, Iterable<T>) rather than `Collection<E>#addAll(Collection<? extends E>)`, resulting in the error you described due to the lack of wildcard on the iterable parameter to the DGM addAll method. > Collection addAll fails CompileStatic type checking when adding a collection > of subtypes > ---------------------------------------------------------------------------------------- > > Key: GROOVY-7774 > URL: https://issues.apache.org/jira/browse/GROOVY-7774 > Project: Groovy > Issue Type: Bug > Components: groovy-jdk > Affects Versions: 2.4.3 > Environment: Windows, Java 8. > Reporter: Darren Hurt > > Suppose X is an interface and Y an interface such that Y extends X > The following code throws a compilation error (the outer class is annotated > as @CompileStatic). > Set<X> set = new HashSet<X>() > Set<Y> toAdd = ...... > set.addAll(toAdd) > However, the following works, which to me is inconsistent: > Set<X> set = new HashSet<X>() > Set<Y> toAdd = ...... > for(Y y in toAdd) > { > set.add(y) > } -- This message was sent by Atlassian JIRA (v6.3.4#6332)