Issue
How can I determine if a variable exists from within the Groovy code running in the Scripting Engine?
The variable was put by rel="noreferrer">ScriptEngine's put method
Solution
In the groovy.lang.Script there is a method public Binding getBinding()
. See also groovy.lang.Binding with method public boolean hasVariable(String name)
.
Thus you can simple check variable existence like
if (binding.hasVariable('superVariable')) {
// your code here
}
Answered By - Aliaksandr Pyrkh
Answer Checked By - Cary Denson (JavaFixing Admin)