Nashorn is a runtime environment for programs written in ECMAScript 5.1.
javax.script
package. Usually, you'll obtain a
ScriptEngine
instance for Nashorn using:
import javax.script.*; ... ScriptEngine nashornEngine = new ScriptEngineManager().getEngineByName("nashorn");and then use it just as you would any other JSR-223 script engine. See
jdk.nashorn.api.scripting
package
for details.
List
s support indexed access to their elements through the property accessors,
and Map
s support both property and element access through both dot and square-bracket property
accessors, with the difference being that dot operator gives precedence to object properties (its fields and properties
defined as getXxx
and setXxx
methods) while the square bracket operator gives precedence to map
elements. Native Java arrays expose the length
property.
Number
,
CharSequence
, and Boolean
objects. While the most often used number type is
Double
and the most often used string type is String
, don't rely on it as various
internal optimizations cause other subclasses of Number
and internal implementations of CharSequence
to
be used.
java.lang.Object
,
Nashorn objects are passed without any conversion whatsoever; specifically if the JavaScript value being passed is of
primitive string type, you can only rely on it being a java.lang.CharSequence
, and if the value is a number, you
can only rely on it being a java.lang.Number
. If the Java method declared parameter type is more specific (e.g.
java.lang.String
or java.lang.Double
), then Nashorn will of course ensure the required type is passed.
Java
objectJava
that is the primary API entry point into Java
platform-specific functionality. You can use it to create instances of Java classes, convert from Java arrays to native
arrays and back, and so on.
Java
, Nashorn also exposes some other non-standard built-in objects:
JSAdapter
, JavaImporter
, Packages
Package | Description |
---|---|
jdk.nashorn.api.scripting |
This package provides the
javax.script integration, which is the preferred way to use Nashorn. |
jdk.nashorn.api.tree |
Nashorn parser API provides interfaces to represent ECMAScript source code
as abstract syntax trees (AST) and Parser to parse ECMAScript source scripts.
|
Submit a bug or feature
Java is a trademark or registered trademark of Oracle and/or its affiliates in the US and other countries.
Copyright © 2014, 2017, Oracle and/or its affiliates. 500 Oracle Parkway
Redwood Shores, CA 94065 USA. All rights reserved.
DRAFT 9-Debian+0-9b153-2