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

Target Typing for empty collections should work for field/property initialisers

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 2.4.13
    • None
    • None

    Description

      import groovy.transform.*
      @CompileStatic
      @ToString(includeFields=true)
      class Foo {
          List<String> propWithGen = ['propWithGen'] ?: []
          List propNoGen = ['propNoGen'] ?: []
          private List<String> fieldGen = ['fieldGen'] ?: []
          def bar() {
              this.propNoGen = ['notDecl'] ?: [] // not applicable here
              List<String> localVar = ['localVar'] ?: []
              localVar
          }
      }
      
      def foo = new Foo()
      assert foo.bar() == ['localVar']
      assert foo.toString() == 'Foo([propWithGen], [notDecl], [fieldGen])'
      

      Attachments

        Issue Links

          Activity

            People

              paulk Paul King
              paulk Paul King
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: