Save This Page
Home » groovy-src-1.6.3 » groovy » lang » [javadoc | source]
groovy.lang
abstract public class: Closure [javadoc | source]
java.lang.Object
   groovy.lang.GroovyObjectSupport
      groovy.lang.Closure

All Implemented Interfaces:
    Cloneable, Runnable, Serializable, GroovyObject

Direct Known Subclasses:
    WritableClosure, IteratorClosureAdapter, CurriedClosure, MethodClosure

Represents any closure object in Groovy.

Groovy allows instances of Closures to be called in a short form. For example:

def a = 1
def c = {a}
assert c() == 1
To be able to use a Closure in this way with your own subclass, you need to provide a doCall method with any signature you want to. This ensures that #getMaximumNumberOfParameters() and #getParameterTypes() will work too without any additional code. If no doCall method is provided a closure must be used in its long form like
def a = 1
def c = {a}
assert c.call() == 1
Field Summary
public static final  int OWNER_FIRST    With this resolveStrategy set the closure will attempt to resolve property references to the owner first 
public static final  int DELEGATE_FIRST    With this resolveStrategy set the closure will attempt to resolve property references to the delegate first 
public static final  int OWNER_ONLY    With this resolveStrategy set the closure will resolve property references to the owner only and not call the delegate at all 
public static final  int DELEGATE_ONLY    With this resolveStrategy set the closure will resolve property references to the delegate only and entirely bypass the owner 
public static final  int TO_SELF    With this resolveStrategy set the closure will resolve property references to itself and go through the usual MetaClass look-up process. This allows the developer to override getProperty using ExpandoMetaClass of the closure itself 
public static final  int DONE     
public static final  int SKIP     
protected  Class[] parameterTypes     
protected  int maximumNumberOfParameters     
Constructor:
 public Closure(Object owner) 
 public Closure(Object owner,
    Object thisObject) 
Method from groovy.lang.Closure Summary:
asWritable,   call,   call,   call,   clone,   curry,   getDelegate,   getDirective,   getMaximumNumberOfParameters,   getOwner,   getParameterTypes,   getProperty,   getResolveStrategy,   getThisObject,   isCase,   run,   setDelegate,   setDirective,   setProperty,   setResolveStrategy,   throwRuntimeException
Methods from groovy.lang.GroovyObjectSupport:
getMetaClass,   getProperty,   invokeMethod,   setMetaClass,   setProperty
Methods from java.lang.Object:
equals,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   wait
Method from groovy.lang.Closure Detail:
 public Closure asWritable() 
 public Object call() 
    Invokes the closure without any parameters, returning any value if applicable.
 public Object call(Object[] args) 
 public Object call(Object arguments) 
    Invokes the closure, returning any value if applicable.
 public Object clone() 
 public Closure curry(Object[] arguments) 
    Support for closure currying
 public Object getDelegate() 
 public int getDirective() 
 public int getMaximumNumberOfParameters() 
 public Object getOwner() 
 public Class[] getParameterTypes() 
 public Object getProperty(String property) 
 public int getResolveStrategy() 
    Gets the strategy which the closure users to resolve methods and properties
 public Object getThisObject() 
 public boolean isCase(Object candidate) 
 public  void run() 
 public  void setDelegate(Object delegate) 
    Allows the delegate to be changed such as when performing markup building
 public  void setDirective(int directive) 
 public  void setProperty(String property,
    Object newValue) 
 public  void setResolveStrategy(int resolveStrategy) 
    Sets the strategy which the closure uses to resolve property references. The default is Closure.OWNER_FIRST
 protected static Object throwRuntimeException(Throwable throwable)