Created
August 14, 2022 19:55
-
-
Save sandipchitale/5fbfc7465ec1132169a2f7a7eb861f28 to your computer and use it in GitHub Desktop.
Groover closue delegate example #groovy #closure
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
def append(String s) { | |
println "Appending: ${s}" | |
} | |
def closure = { | |
println owner | |
println delegate | |
append 'Hello' | |
append 'World' | |
} | |
closure() | |
def sb = new StringBuilder(); | |
closure.delegate = sb; | |
closure() | |
println sb | |
closure.resolveStrategy = Closure.OWNER_FIRST | |
println sb | |
closure() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment