Posted By

narkisr on 02/07/09


Tagged

this groovy Delegate owner


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

laurenceosx


Groovy delegate, owner, this references.


 / Published in: Groovy
 

This, owner, and delegate: this : as in Java, this refers to the instance of the enclosing class where a Closure is defined owner : the enclosing object (this or a surrounding closure) delegate : by default the same as owner, but changeable. (http://groovy.codehaus.org/Closures).

  1. class Class1 {
  2. def closure = {
  3. println delegate.class.name
  4. def nestedClos = {
  5. println owner.class.name
  6. }
  7. nestedClos()
  8. }
  9. }
  10.  
  11. def clos = new Class1().closure
  12. clos.delegate = this
  13. clos()
  14. /*prints:
  15.  Class1
  16.  Script1
  17.  Class1$_closure1 */

Report this snippet  

You need to login to post a comment.