Last active
December 14, 2015 19:39
-
-
Save rodhilton/5138266 to your computer and use it in GitHub Desktop.
Some weirdness with groovy binding
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class BindingExample { | |
| public static void main(String[] args) { | |
| Closure closure1 = { | |
| printit.call("Hello from closure 1") | |
| } | |
| Closure closure2 = { | |
| printit("Hello from closure 2") | |
| } | |
| Closure printit = { s -> | |
| println("printing: "+s) | |
| } | |
| Binding binding = new Binding() | |
| binding.setVariable("printit", printit) | |
| closure1.delegate = binding | |
| closure2.delegate = binding | |
| closure1() //This works fine | |
| closure2() //This does not. | |
| //Why does .call() work and () alone not? Most documentation says they're the same. | |
| } | |
| } |
Author
rodhilton
commented
Mar 11, 2013
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment