Skip to content

Instantly share code, notes, and snippets.

@melix
Created October 17, 2012 02:45
Show Gist options
  • Save melix/3903438 to your computer and use it in GitHub Desktop.
Save melix/3903438 to your computer and use it in GitHub Desktop.
DelegatesTo parameter
class Foo {
def foo() { println 'Called foo' }
}
@groovy.transform.CompileStatic
def with(Object target, @DelegatesTo(parameter='target') Closure arg) {
arg.delegate = target
arg()
}
@groovy.transform.CompileStatic
def test() {
def obj = new Foo()
with(obj) { foo() }
}
test()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment