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

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

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 2.4.13
    • Component/s: None
    • Labels:
      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

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

                Dates

                • Created:
                  Updated:
                  Resolved: