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

@Lazy should work in combination with @Delegate

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 2.4.1
    • Component/s: None
    • Labels:
      None

      Description

      @Delegate uses the delegate field directly but that won't have been set if also using @Lazy. We might eventually allow this to be customizable, e.g. with a flag like 'direct = false' or 'forceDirect' or 'useDelegateField', but for now we should at least just fix the common case.

      Expected behavior:

      class Foo {
        private @Delegate @Lazy ArrayList list = ['bar', 'baz']
        // fragile: $list is an internal implementation detail that may change
        def getInternalDelegate() { $list }
      }
      
      def f = new Foo()
      assert f.internalDelegate == null
      assert f.size() == 2
      assert f.internalDelegate == ['bar', 'baz']
      

        Attachments

          Activity

            People

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

              Dates

              • Created:
                Updated:
                Resolved: