software development for the
existentially challenged
Older | Newer Older | Newer
Closure's visibility to itself
comment share
Problem: Within a closure, trying to reference a variable that references itself fails. For instance:

def items = []
def walker = { child ->
                items << child
                items << walker
         }
This doesn't work: walker is not found within the closure. Defining and assigning the variable does work:
def items = []
def walker
walker = { child ->
                items << child
                items << walker
         } 

0 comments:

Post a Comment

What is this site?!

t (a professional software developer for a big company) writes about software development and stuff. Unix, Java, Groovy, OS X, and lots of open source libraries and tools.