File tree Expand file tree Collapse file tree 2 files changed +29
-0
lines changed Expand file tree Collapse file tree 2 files changed +29
-0
lines changed Original file line number Diff line number Diff line change
1
+ var fun = function ( name ) {
2
+ print ( 'Hi there, ' + name ) ;
3
+ return "success" ;
4
+ } ;
Original file line number Diff line number Diff line change
1
+ package com .winterbe .java8 ;
2
+
3
+ import javax .script .Invocable ;
4
+ import javax .script .ScriptEngine ;
5
+ import javax .script .ScriptEngineManager ;
6
+ import javax .script .ScriptException ;
7
+ import java .io .FileNotFoundException ;
8
+ import java .io .FileReader ;
9
+
10
+ /**
11
+ * @author Benjamin Winterberg
12
+ */
13
+ public class Nashorn1 {
14
+
15
+ public static void main (String [] args ) throws ScriptException , FileNotFoundException , NoSuchMethodException {
16
+ ScriptEngine engine = new ScriptEngineManager ()
17
+ .getEngineByName ("nashorn" );
18
+ engine .eval (new FileReader ("res/nashorn1.js" ));
19
+
20
+ Invocable invocable = (Invocable ) engine ;
21
+ Object result = invocable .invokeFunction ("fun" , "Peter Parker" );
22
+ System .out .println (result );
23
+ }
24
+
25
+ }
You can’t perform that action at this time.
0 commit comments