Evaluate a String-Based Script
Because a script engine is represented as an instance of a class that implements interface ScriptEngine or that subclasses the AbstractScriptEngine class (which implements ScriptEngine), you can invoke any of six eval() methods to evaluate scripts. For example, you might invoke public Object eval(String script) to evaluate a string-based script. This method returns the script's result as an object—null if there is no result. An instance of the checked ScriptException class is thrown if the script has an error. Take a look at Listing 2.
Listing 2: ScriptDemo2.java
ScriptDemo2 creates the following output:
Hello, World Object value: null Object value: -1.0 Object is Double: true