Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-7774

Collection addAll fails CompileStatic type checking when adding a collection of subtypes

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.4.3
    • 2.4.8
    • groovy-jdk
    • None
    • Windows, Java 8.

    Description

      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)
      }
      

      Attachments

        Issue Links

          Activity

            People

              paulk Paul King
              darren.hurt@gmail.com Darren Hurt
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: