groovy-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF GitHub Bot (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (GROOVY-7774) Collection addAll fails CompileStatic type checking when adding a collection of subtypes
Date Mon, 01 Aug 2016 04:36:20 GMT

    [ https://issues.apache.org/jira/browse/GROOVY-7774?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15401517#comment-15401517
] 

ASF GitHub Bot commented on GROOVY-7774:
----------------------------------------

Github user paulk-asert commented on a diff in the pull request:

    https://github.com/apache/groovy/pull/376#discussion_r72923109
  
    --- Diff: src/main/org/codehaus/groovy/runtime/DefaultGroovyMethods.java ---
    @@ -5169,12 +5170,13 @@ public static Map groupBy(Object[] self, List<Closure> closures)
{
          * @return a new Map grouped by keys
          * @since 1.0
          */
    -    public static <G, K, V> Map<G, Map<K, V>> groupBy(Map<K, V>
self, @ClosureParams(MapEntryOrKeyValue.class) Closure<G> closure) {
    -        final Map<G, List<Map.Entry<K, V>>> initial = groupEntriesBy(self,
closure);
    -        final Map<G, Map<K, V>> answer = new LinkedHashMap<G, Map<K,
V>>();
    -        for (Map.Entry<G, List<Map.Entry<K, V>>> outer : initial.entrySet())
{
    +    public static <G, K, V> Map<G, Map<? extends  K, ? extends V>>
groupBy(
    +            Map<K, V> self, @ClosureParams(MapEntryOrKeyValue.class) Closure<G>
closure) {
    --- End diff --
    
    It isn't exactly what I would like but groupBy calls putAll and the other changes are
to make Java happy. We might have to do some casting and suppress some warnings instead.


> 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).
> {code}
> Set<X> set = new HashSet<X>()
> Set<Y> toAdd = ......
> set.addAll(toAdd)
> {code}
> However, the following works, which to me is inconsistent:
> {code}
> Set<X> set = new HashSet<X>()
> Set<Y> toAdd = ......
> for(Y y in toAdd) {
>   set.add(y)
> }
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Mime
View raw message