In a recent post I took a look at how Java 8 and Scala implemented Lambda expressions. As we know Java 8 is not only introducing improvements to the javac compiler, It’s also introducing a new one altogether - Nashorn.

This new engine is meant to replace Java’s existing JavaScript interpreter Rhino. This is supposed to bring the JVM to the forefront when it comes to executing JavaScript at speed, right there with V8s of the world (hopefully we’ll finally get past that car to carpet thing :)) So, I thought it would be a good time to bring Nashorn to the mix as well by taking a look under the hood, and see how it compiles Lambda expressions (especially compared to Java and Scala).

The lambda expression we’ll be looking at is similar to the one we tested with Java and Scala.

Here’s the code -

ScriptEngineManager manager = new ScriptEngineManager();
ScriptEngine engine = manager.getEngineByName("nashorn");

String js;

js = "var map = \n";
js += "var names = [\"john\", \"jerry\", \"bob\"]\n";
js += "var a =, function(name) { return name.length() })\n";
js += "print(a)";


Seems innocent enough you’d think. But just wait and see...

Read the full post here