@@ -0,0 +1,1106 @@
+package com.winterbe.java8;%0A%0Aimport javax.script.Invocable;%0Aimport javax.script.ScriptEngine;%0Aimport javax.script.ScriptEngineManager;%0Aimport javax.script.ScriptException;%0A%0A/**%0A * @author Benjamin Winterberg%0A */%0Apublic class Nashorn7 %7B%0A%0A    public static class Person %7B%0A        private String name;%0A%0A        public String getName() %7B%0A            return name;%0A        %7D%0A%0A        public void setName(String name) %7B%0A            this.name = name;%0A        %7D%0A%0A        public int getLengthOfName() %7B%0A            return name.length();%0A        %7D%0A    %7D%0A%0A    public static void main(String%5B%5D args) throws ScriptException, NoSuchMethodException %7B%0A        ScriptEngine engine = new ScriptEngineManager().getEngineByName(%22nashorn%22);%0A        engine.eval(%22function foo(predicate, obj) %7B return !!(eval(predicate)); %7D;%22);%0A%0A        Invocable invocable = (Invocable) engine;%0A%0A        Person person = new Person();%0A        person.setName(%22Hans%22);%0A%0A        String predicate = %22obj.getLengthOfName() %3E= 4%22;%0A        Object result = invocable.invokeFunction(%22foo%22, predicate, person);%0A        System.out.println(result);%0A    %7D%0A%0A%7D%0A

Add another nashorn sample of dynamically invoking java code at runtime