Class CompiledScript
java.lang.Object
javax.script.CompiledScript
public abstract class CompiledScript extends Object
Extended by classes that store results of compilations. State might be stored in the form of Java classes, Java class files or scripting language opcodes. The script may be executed repeatedly without reparsing.
Each
Each
CompiledScript is associated with a ScriptEngine -- A call to an eval method of the CompiledScript causes the execution of the script by the ScriptEngine. Changes in the state of the ScriptEngine caused by execution of the CompiledScript may visible during subsequent executions of scripts by the engine.- Since:
- 1.6
Constructor Summary
| Constructor | Description |
|---|---|
CompiledScript() |
Constructor for subclasses to call. |
Method Summary
| Modifier and Type | Method | Description |
|---|---|---|
Object |
eval() |
Executes the program stored in the CompiledScript object. |
Object |
eval |
Executes the program stored in the CompiledScript object using the supplied Bindings of attributes as the ENGINE_SCOPE of the associated ScriptEngine during script execution. |
abstract Object |
eval |
Executes the program stored in this CompiledScript object. |
abstract ScriptEngine |
getEngine() |
Returns the ScriptEngine whose compile method created this CompiledScript. |
Methods declared in class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait | Modifier and Type | Method | Description |
|---|---|---|
protected Object |
clone() |
Creates and returns a copy of this object. |
boolean |
equals |
Indicates whether some other object is "equal to" this one. |
protected void |
finalize() |
Deprecated, for removal: This API element is subject to removal in a future version. Finalization is deprecated and subject to removal in a future release. |
final Class |
getClass() |
Returns the runtime class of this Object. |
int |
hashCode() |
Returns a hash code value for this object. |
final void |
notify() |
Wakes up a single thread that is waiting on this object's monitor. |
final void |
notifyAll() |
Wakes up all threads that are waiting on this object's monitor. |
String |
toString() |
Returns a string representation of the object. |
final void |
wait() |
Causes the current thread to wait until it is awakened, typically by being notified or interrupted. |
final void |
wait |
Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed. |
final void |
wait |
Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed. |
Constructor Details
CompiledScript
public CompiledScript()
Constructor for subclasses to call.
Method Details
eval
public abstract Object eval(ScriptContext context) throws ScriptException
Executes the program stored in this
CompiledScript object.- Parameters:
-
context- AScriptContextthat is used in the same way as theScriptContextpassed to theevalmethods ofScriptEngine. - Returns:
- The value returned by the script execution, if any. Should return
nullif no value is returned by the script execution. - Throws:
-
ScriptException- if an error occurs. -
NullPointerException- if context is null.
eval
public Object eval(Bindings bindings) throws ScriptException
Executes the program stored in the
CompiledScript object using the supplied Bindings of attributes as the ENGINE_SCOPE of the associated ScriptEngine during script execution. If bindings is null, then the effect of calling this method is same as that of eval(getEngine().getContext()). . The GLOBAL_SCOPE Bindings, Reader and Writer associated with the default ScriptContext of the associated ScriptEngine are used.
- Parameters:
-
bindings- The bindings of attributes used for theENGINE_SCOPE. - Returns:
- The return value from the script execution
- Throws:
-
ScriptException- if an error occurs.
eval
public Object eval() throws ScriptException
Executes the program stored in the
CompiledScript object. The default ScriptContext of the associated ScriptEngine is used. The effect of calling this method is same as that of eval(getEngine().getContext()).- Returns:
- The return value from the script execution
- Throws:
-
ScriptException- if an error occurs.
getEngine
public abstract ScriptEngine getEngine()
Returns the
ScriptEngine whose compile method created this CompiledScript. The CompiledScript will execute in this engine.- Returns:
- The
ScriptEnginethat created thisCompiledScript
© 1993, 2025, Oracle and/or its affiliates. All rights reserved.
Documentation extracted from Debian's OpenJDK Development Kit package.
Licensed under the GNU General Public License, version 2, with the Classpath Exception.
Various third party code in OpenJDK is licensed under different licenses (see Debian package).
Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.