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

confused by the def used in closure

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Won't Fix
    • 1.0-JSR-2
    • 1.0-JSR-4
    • class generator
    • None
    • All

    Description

      def env = ['x':2, 'y':0]
      def c =

      { def x, y println x; println y; }

      c.setDelegate(env)
      c()
      println env.x
      println env.y

      /*output
      null
      null
      2
      0
      /*
      but

      def env = ['x':2, 'y':0]
      def c =

      { println x; println y; }

      c.setDelegate(env)
      c()
      println env.x
      println env.y

      //output
      2
      0
      2
      0

      Attachments

        Activity

          People

            blackdrag Jochen Theodorou
            wangbin wangbin
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: