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

Problem converting primitive array to a Set

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.8.4
    • 1.8.5, 2.0-beta-2, 1.7.11
    • None
    • None

    Description

      When I try to convert a primitive array to java.util.Set using the "as" operator, it looks like Groovy tries to create an instance of java.util.Set (as opposed to creating an instance of some class which implements java.util.Set).

      demo.groovy
      def intArray = [1, 2, 3] as int[]
      def setOfInt = intArray as Set
      println setOfInt
      
      conversion_problem $ groovy -version
      Groovy Version: 1.8.4 JVM: 1.6.0_29
      conversion_problem $ groovy demo.groovy 
      Caught: org.codehaus.groovy.runtime.typehandling.GroovyCastException: Could not instantiate instance of: java.util.Set. Reason: java.lang.InstantiationException: java.util.Set
      org.codehaus.groovy.runtime.typehandling.GroovyCastException: Could not instantiate instance of: java.util.Set. Reason: java.lang.InstantiationException: java.util.Set
      	at demo.run(demo.groovy:2)
      

      Attachments

        Activity

          People

            melix Cédric Champeau
            brownj Jeff Brown
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: