DevOps / BeanShell Interview questions
How do you exchange data between a host Java application and an embedded BeanShell script?
The host application passes data into the script's namespace using the Interpreter's set() method, making a Java object or primitive value available under a chosen variable name for the script to read or modify.
After the script runs, via eval() or source(), the host application retrieves any resulting data using the Interpreter's get() method, pulling a variable's current value back out of the script's namespace into Java code.
Because the objects passed via set() are real Java object references, not copies, a script that calls methods on a passed-in mutable object can affect that same object as seen by the host application afterward, which is a common, deliberate pattern for letting a script modify shared state rather than only returning a value through eval()'s return value.
More Related questions...