[Java] Class Binding

  • groovy.lang.Binding

Represents the variable bindings of a script which can be altered from outside the script object or created outside of a script and passed into it.

Binding instances are not supposed to be used in a multi-threaded context.

Authors:
James Strachan

Constructor Summary

Constructors
Constructor and description
Binding ()
Binding (Map variables)
Binding (String[] args)
A helper constructor used in main(String[]) method calls

Methods Summary

Methods
Type Params Return Type Name and description
Object getProperty(String property)
Overloaded to make variables appear as bean properties or via the subscript operator
Object getVariable(String name)
@param name the name of the variable to lookup
Map getVariables()
boolean hasVariable(String name)
Simple check for whether the binding contains a particular variable or not.
void setProperty(String property, Object newValue)
@todo we should check if we have the property with the metaClass instead of try/catch
void setVariable(String name, Object value)
Sets the value of the given variable

Inherited Methods Summary

Inherited Methods
Methods inherited from class Name
class GroovyObjectSupport getMetaClass, getProperty, invokeMethod, setMetaClass, setProperty
class Object wait, wait, wait, equals, toString, hashCode, getClass, notify, notifyAll

Constructor Detail

public Binding()

public Binding(Map variables)

public Binding(String[] args)

A helper constructor used in main(String[]) method calls

Parameters:
args - are the command line arguments from a main()

Method Detail

public Object getProperty(String property)

Overloaded to make variables appear as bean properties or via the subscript operator

public Object getVariable(String name)

Parameters:
name - the name of the variable to lookup
Returns:
the variable value

public Map getVariables()

public boolean hasVariable(String name)

Simple check for whether the binding contains a particular variable or not.

Parameters:
name - the name of the variable to check for

public void setProperty(String property, Object newValue)

todo:
we should check if we have the property with the metaClass instead of try/catch

public void setVariable(String name, Object value)

Sets the value of the given variable

Parameters:
name - the name of the variable to set
value - the new value for the given variable

© 2003-2020 The Apache Software Foundation
Licensed under the Apache license.
https://docs.groovy-lang.org/2.4.21/html/gapi/groovy/lang/Binding.html