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

Spread dot operator doesn't work on arrays

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.1-rc-3
    • 1.1-rc-3
    • None
    • None

    Description

      This code works:

      class Book1 { String name }
      class Book2 { String name }
      class Book3 { String name }
      
      println Book1.metaClass
      println Book2.metaClass
      println Book3.metaClass
      
      books = [Book1, Book2, Book3] 
      
      books*.metaClass*.foo = { "hello" }
      
      b = new Book1()
      b.foo()
      

      But this doesn't:

      class Book1 { String name }
      class Book2 { String name }
      class Book3 { String name }
      
      println Book1.metaClass
      println Book2.metaClass
      println Book3.metaClass
      
      books = [Book1, Book2, Book3] as Object[]
      
      books*.metaClass*.foo = { "hello" }
      
      b = new Book1()
      b.foo()
      

      The difference is one is an array one is a collection. The spread dot operator should work on arrays and collections in the same way

      Attachments

        Activity

          People

            ait Alex Tkachman
            graemerocher Graeme Rocher
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: