use of com.winterbe.java8.samples.lambda.Person in project java8-tutorial by winterbe.
the class Nashorn8 method main.
public static void main(String[] args) throws ScriptException, NoSuchMethodException {
NashornScriptEngine engine = (NashornScriptEngine) new ScriptEngineManager().getEngineByName("nashorn");
engine.eval("load('res/nashorn8.js')");
// [object global]
engine.invokeFunction("evaluate1");
// [object Object]
engine.invokeFunction("evaluate2");
// Foobar
engine.invokeFunction("evaluate3", "Foobar");
// [object global] <- ???????
engine.invokeFunction("evaluate3", new Person("John", "Doe"));
}
use of com.winterbe.java8.samples.lambda.Person in project java8-tutorial by winterbe.
the class Nashorn1 method main.
public static void main(String[] args) throws Exception {
ScriptEngine engine = new ScriptEngineManager().getEngineByName("nashorn");
engine.eval(new FileReader("res/nashorn1.js"));
Invocable invocable = (Invocable) engine;
Object result = invocable.invokeFunction("fun1", "Peter Parker");
System.out.println(result);
System.out.println(result.getClass());
invocable.invokeFunction("fun2", new Date());
invocable.invokeFunction("fun2", LocalDateTime.now());
invocable.invokeFunction("fun2", new Person());
}
Aggregations