Groovy web console

subscribe to the feed Subscribe
to this
site
closure (via #groovywebconsole)
tweet this snippet Tweet
this
script

closure

Published 5 months ago by mjb
Actions  ➤ Edit in console Back to console Show/hide line numbers View recent scripts
class Foo {
    Closure<String> cl = { String a -> 
        delegate = (Foo)delegate
        return "Say: ${delegate.bar(a)}" 
    }

    String bar(String a) {
        return "Hello ${a}."
    }

}

Foo f = new Foo()
f.getCl().setDelegate(f)
String output = f.getCl()("Squirrel")
println(output)