{"id":23423,"date":"2014-03-31T01:00:32","date_gmt":"2014-03-30T22:00:32","guid":{"rendered":"http:\/\/www.javacodegeeks.com\/?p=23423"},"modified":"2014-04-03T12:13:54","modified_gmt":"2014-04-03T09:13:54","slug":"the-dark-side-of-lambda-expressions-in-java-8","status":"publish","type":"post","link":"https:\/\/www.javacodegeeks.com\/2014\/03\/the-dark-side-of-lambda-expressions-in-java-8.html","title":{"rendered":"The Dark Side Of Lambda Expressions in Java 8"},"content":{"rendered":"<p><a href=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2014\/03\/blog_lambada_2.png\"><img decoding=\"async\" class=\"alignright size-medium wp-image-23492\" alt=\"blog_lambada_2\" src=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2014\/03\/blog_lambada_2-300x155.png\" width=\"300\" height=\"155\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2014\/03\/blog_lambada_2-300x155.png 300w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2014\/03\/blog_lambada_2.png 580w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>This post may not make me any new friends. Oh well, I was never really popular at school anyway. But let\u2019s get to the point. Java 8\u2019s biggest feature in terms of the language is undoubtedly Lambda expressions. It\u2019s been a flagship\u00a0feature for functional languages such as Scala and Clojure for a few years, and now Java has finally joined in.<\/p>\n<p>The second biggest feature (depending of course on who you ask) is <strong>Nashorn<\/strong> \u2013 the new JVM JavaScript engine that\u2019s supposed to bring Java up to par with other JS engines such as V8 and its node.js container.<\/p>\n<p>But these <a href=\"http:\/\/www.javacodegeeks.com\/2014\/03\/5-features-in-java-8-that-will-change-how-you-code.html\" target=\"_blank\">new features<\/a> have a dark side to them.<\/p>\n<p>I\u2019ll explain. The Java platform is built out of two main components. The JRE, which JIT compiles and executes bytecode, and the JDK which contains dev tools and the javac source compiler. These two components are fairly (but not fully) decoupled, which is what enables folks to write their own JVM languages, with Scala rising to prominence in the last few years. And therein lies some of the problem.<\/p>\n<p>The JVM was built to be language agnostic in the sense that it can execute code written in any language, as long as it can be translated into bytecode. The bytecode specification itself is fully OO, and was designed to closely match the Java language. That means that bytecode compiled from Java source will pretty much resemble it structurally.<\/p>\n<p>But the farther away you get from Java \u2013 the more that distance grows. When you look at <strong>Scala<\/strong> which is a functional language, the distance between the source code and the executed bytecode is pretty big. Large amounts of synthetic classes, methods and variables are added by the compiler to get the JVM to execute the semantics and flow controls required by the language.<\/p>\n<p>When you look at fully dynamic languages such as <strong>JavaScript<\/strong>, that distance becomes huge.<\/p>\n<p>And now with Java 8, this is beginning to creep into Java as well.<\/p>\n<h2>So why should I\u00a0care?<\/h2>\n<p>I wish this could be a theoretical discussion, that while interesting, has no practical implication on our everyday work. Unfortunately it does, and in a very big way. With the push to add new elements into Java, the distance between your code and the runtime grows, which means that what you\u2019re writing and what you\u2019re debugging will be two different things.<\/p>\n<p>To see how let\u2019s (re)visit the example below.<\/p>\n<h2>Java 6 &amp; 7<\/h2>\n<p>This is the traditional method by which we would iterate over a list of strings to map their lengths.<\/p>\n<pre class=\" brush:java\">\/\/ simple check against empty strings\r\npublic static int check(String s) {\r\n    if (s.equals(\"\")) {\r\n        throw new IllegalArgumentException();\r\n    }\r\n    return s.length();\r\n}\r\n \r\n\/\/map names to lengths\r\n \r\nList lengths = new ArrayList();\r\n \r\nfor (String name : Arrays.asList(args)) {\r\n    lengths.add(check(name));\r\n}<\/pre>\n<p>This will throw an exception if an empty string is passed. The stack trace will look like &#8211;<\/p>\n<pre class=\" brush:java\">at LmbdaMain.check(LmbdaMain.java:19)\r\nat LmbdaMain.main(LmbdaMain.java:34)<\/pre>\n<p>Here we see a 1:1 correlation between the stack trace we see and the code we wrote, which makes debugging this call stack pretty straightforward. This is what most Java devs are used to.<\/p>\n<p>Now let\u2019s look at Scala and Java 8.<\/p>\n<h2>Scala<\/h2>\n<p>Let\u2019s look at the same code in Scala. Here we\u2019ve got two big changes. The first is the use of a Lambda expression to map the lengths, and the second is that the iteration is carried out by the framework (i.e. internal iteration).<\/p>\n<pre class=\" brush:scala\">val lengths = names.map(name =&gt; check(name.length))<\/pre>\n<p>Here we really start to notice the difference between how the code you wrote looks, and how the JVM (and you) will see it at run time. If an exception is thrown, the call stack is <strong>an order of magnitude longer<\/strong>, and much harder to understand.<\/p>\n<pre class=\" brush:scala\">at Main$.check(Main.scala:6)\r\nat Main$$anonfun$1.apply(Main.scala:12)\r\nat Main$$anonfun$1.apply(Main.scala:12)\r\nat scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:244)\r\nat scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:244)\r\nat scala.collection.immutable.List.foreach(List.scala:318)\r\nat scala.collection.TraversableLike$class.map(TraversableLike.scala:244)\r\nat scala.collection.AbstractTraversable.map(Traversable.scala:105)\r\nat Main$delayedInit$body.apply(Main.scala:12)\r\nat scala.Function0$class.apply$mcV$sp(Function0.scala:40)\r\nat scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:12)\r\nat scala.App$$anonfun$main$1.apply(App.scala:71)\r\nat scala.App$$anonfun$main$1.apply(App.scala:71)\r\nat scala.collection.immutable.List.foreach(List.scala:318)\r\nat scala.collection.generic.TraversableForwarder$class.foreach(TraversableForwarder.scala:32)\r\nat scala.App$class.main(App.scala:71)\r\nat Main$.main(Main.scala:1)\r\nat Main.main(Main.scala)<\/pre>\n<p>* Remember, this example is very simple. With real-world nested Lambdas and complex structures you\u2019ll be looking at much longer synthetic call stacks, from which you\u2019ll need to understand what happened.<\/p>\n<p>This has long been an issue with Scala, and one of the reasons we built the <a href=\"http:\/\/stackifier.takipi.com\/scala.html\" target=\"_blank\">Scala Stackifier<\/a>.<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<h2>And now in Java 8<\/h2>\n<p>Up until now Java developers were pretty immune to this. This will change as Lambda expressions become an integral part of Java. Let\u2019s look at the corresponding Java 8 code, and the resulting call stack.<\/p>\n<pre class=\" brush:java\">Stream lengths = names.stream().map(name -&gt; check(name));\r\n\r\nat LmbdaMain.check(LmbdaMain.java:19)\r\nat LmbdaMain.lambda$0(LmbdaMain.java:37)\r\nat LmbdaMain$$Lambda$1\/821270929.apply(Unknown Source)\r\nat java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)\r\nat java.util.Spliterators$ArraySpliterator.forEachRemaining(Spliterators.java:948)\r\nat java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:512)\r\nat java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:502)\r\nat java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708)\r\nat java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)\r\nat java.util.stream.LongPipeline.reduce(LongPipeline.java:438)\r\nat java.util.stream.LongPipeline.sum(LongPipeline.java:396)\r\nat java.util.stream.ReferencePipeline.count(ReferencePipeline.java:526)\r\nat LmbdaMain.main(LmbdaMain.java:39)<\/pre>\n<p>This is becoming pretty similar to Scala. We\u2019re paying the price for shorter, more concise code with more complex debugging, and longer synthetic call stacks.<\/p>\n<p>The reason is that while javac has been extended to support Lambda functions, the JVM still remains <strong>oblivious<\/strong> to them. This has been a design decision by the Java folks in order to to keep the JVM operating at a lower-level, and without introducing new elements into its specification.<\/p>\n<p>And while you can debate the merits of this decision, it means that as Java developers the cost figuring out these call stacks when we get a ticket now sadly lies on our shoulders, whether we want to or not.<\/p>\n<h2>JavaScript in Java 8<\/h2>\n<p>Java 8 introduces a brand new JavaScript compiler. Now we can finally integrate Java + JS in an efficient and straightforward manner. However, nowhere is the dissonance between the code we write and the code we debug bigger than here.<\/p>\n<p>Here\u2019s the same function in Nashorn &#8211;<\/p>\n<pre class=\" brush:java\">ScriptEngineManager manager = new ScriptEngineManager();\r\nScriptEngine engine = manager.getEngineByName(\"nashorn\");\r\n\r\nString js = \"var map = Array.prototype.map \\n\";\r\njs += \"var a = map.call(names, function(name) { return Java.type(\\\"LmbdaMain\\\").check(name) }) \\n\";\r\njs += \"print(a)\";\r\nengine.eval(js);<\/pre>\n<p>In this case the bytecode code is <a href=\"http:\/\/www.takipiblog.com\/2014\/02\/10\/java-8-compiling-lambda-expressions-in-the-new-nashorn-js-engine\/\" target=\"_blank\">dynamically generated<\/a> at runtime using a nested tree of Lambda expressions. There is very little correlation between our source code, and the resulting bytecode executed by the JVM. The call stack is now <strong>two orders of magnitude longer<\/strong>. In the poignant words of Mr.T \u2013 <a href=\"https:\/\/www.youtube.com\/watch?v=DJnKm6ftPu0\" target=\"_blank\">I pity the fools<\/a> who will need to debug the call stack you\u2019ll be getting here.<\/p>\n<p>Questions, comments? (assuming you can scroll all the way below this call stack). Let me know in the comments section.<\/p>\n<pre class=\" brush:java wrap-lines:false\">LmbdaMain [Java Application]\r\nLmbdaMain at localhost:51287\r\nThread [main] (Suspended (breakpoint at line 16 in LmbdaMain))\r\nLmbdaMain.wrap(String) line: 16\r\n1525037790.invokeStatic_L_I(Object, Object) line: not available\r\n1150538133.invokeSpecial_LL_I(Object, Object, Object) line: not available\r\n538592647.invoke_LL_I(MethodHandle, Object[]) line: not available\r\n1076496284.invokeStatic_LL_L(Object, Object, Object) line: not available\r\nLambdaForm$NamedFunction.invokeWithArguments(Object...) line: 1147\r\nLambdaForm.interpretName(LambdaForm$Name, Object[]) line: 625\r\nLambdaForm.interpretWithArguments(Object...) line: 604\r\n2150540.interpret_I(MethodHandle, Object, Object) line: not available\r\n538592647.invoke_LL_I(MethodHandle, Object[]) line: not available\r\n1076496284.invokeStatic_LL_L(Object, Object, Object) line: not available\r\nLambdaForm$NamedFunction.invokeWithArguments(Object...) line: 1147\r\nLambdaForm.interpretName(LambdaForm$Name, Object[]) line: 625\r\nLambdaForm.interpretWithArguments(Object...) line: 604\r\n92150540.interpret_I(MethodHandle, Object, Object) line: not available\r\n38592647.invoke_LL_I(MethodHandle, Object[]) line: not available\r\n1076496284.invokeStatic_LL_L(Object, Object, Object) line: not available\r\nLambdaForm$NamedFunction.invokeWithArguments(Object...) line: 1147\r\nLambdaForm.interpretName(LambdaForm$Name, Object[]) line: 625\r\nLambdaForm.interpretWithArguments(Object...) line: 604\r\n731260860.interpret_L(MethodHandle, Object, Object) line: not available\r\nLambdaForm$NamedFunction.invoke_LL_L(MethodHandle, Object[]) line: 1108\r\n1076496284.invokeStatic_LL_L(Object, Object, Object) line: not available\r\nLambdaForm$NamedFunction.invokeWithArguments(Object...) line: 1147\r\nLambdaForm.interpretName(LambdaForm$Name, Object[]) line: 625\r\nLambdaForm.interpretWithArguments(Object...) line: 604\r\n2619171.interpret_L(MethodHandle, Object, Object, Object) line: not available\r\n1597655940.invokeSpecial_LLLL_L(Object, Object, Object, Object, Object) line: not available\r\nLambdaForm$NamedFunction.invoke_LLLL_L(MethodHandle, Object[]) line: 1118\r\n1076496284.invokeStatic_LL_L(Object, Object, Object) line: not available\r\nLambdaForm$NamedFunction.invokeWithArguments(Object...) line: 1147\r\nLambdaForm.interpretName(LambdaForm$Name, Object[]) line: 625\r\nLambdaForm.interpretWithArguments(Object...) line: 604\r\n2619171.interpret_L(MethodHandle, Object, Object, Object) line: not available\r\n1353530305.linkToCallSite(Object, Object, Object, Object) line: not available\r\nScript$\\^eval\\_._L3(ScriptFunction, Object, Object) line: 3\r\n1596000437.invokeStatic_LLL_L(Object, Object, Object, Object) line: not available\r\n1597655940.invokeSpecial_LLLL_L(Object, Object, Object, Object, Object) line: not available\r\nLambdaForm$NamedFunction.invoke_LLLL_L(MethodHandle, Object[]) line: 1118\r\n1076496284.invokeStatic_LL_L(Object, Object, Object) line: not available\r\nLambdaForm$NamedFunction.invokeWithArguments(Object...) line: 1147\r\nLambdaForm.interpretName(LambdaForm$Name, Object[]) line: 625\r\nLambdaForm.interpretWithArguments(Object...) line: 604\r\n484673893.interpret_L(MethodHandle, Object, Object, Object, Object, Object) line: not available\r\nLambdaForm$NamedFunction.invoke_LLLLL_L(MethodHandle, Object[]) line: 1123\r\n1076496284.invokeStatic_LL_L(Object, Object, Object) line: not available\r\nLambdaForm$NamedFunction.invokeWithArguments(Object...) line: 1147\r\nLambdaForm.interpretName(LambdaForm$Name, Object[]) line: 625\r\nLambdaForm.interpretWithArguments(Object...) line: 604\r\n282496973.interpret_L(MethodHandle, Object, Object, Object, long, Object) line: not available\r\n93508253.invokeSpecial_LLLLJL_L(Object, Object, Object, Object, Object, long, Object) line: not available\r\n1850777594.invoke_LLLLJL_L(MethodHandle, Object[]) line: not available\r\n1076496284.invokeStatic_LL_L(Object, Object, Object) line: not available\r\nLambdaForm$NamedFunction.invokeWithArguments(Object...) line: 1147\r\nLambdaForm.interpretName(LambdaForm$Name, Object[]) line: 625\r\nLambdaForm.interpretWithArguments(Object...) line: 604\r\n282496973.interpret_L(MethodHandle, Object, Object, Object, long, Object) line: not available\r\n293508253.invokeSpecial_LLLLJL_L(Object, Object, Object, Object, Object, long, Object) line: not available\r\n1850777594.invoke_LLLLJL_L(MethodHandle, Object[]) line: not available\r\n1076496284.invokeStatic_LL_L(Object, Object, Object) line: not available\r\nLambdaForm$NamedFunction.invokeWithArguments(Object...) line: 1147\r\nLambdaForm.interpretName(LambdaForm$Name, Object[]) line: 625\r\nLambdaForm.interpretWithArguments(Object...) line: 604\r\n1840903588.interpret_L(MethodHandle, Object, Object, Object, Object, long, Object) line: not available\r\n2063763486.reinvoke(Object, Object, Object, Object, Object, long, Object) line: not available\r\n850777594.invoke_LLLLJL_L(MethodHandle, Object[]) line: not available\r\n1076496284.invokeStatic_LL_L(Object, Object, Object) line: not available\r\nLambdaForm$NamedFunction.invokeWithArguments(Object...) line: 1147\r\nLambdaForm.interpretName(LambdaForm$Name, Object[]) line: 625\r\nLambdaForm.interpretWithArguments(Object...) line: 604\r\n82496973.interpret_L(MethodHandle, Object, Object, Object, long, Object) line: not available\r\n220309324.invokeExact_MT(Object, Object, Object, Object, long, Object, Object) line: not available\r\nNativeArray$10.forEach(Object, long) line: 1304\r\nNativeArray$10(IteratorAction).apply() line: 124\r\nNativeArray.map(Object, Object, Object) line: 1315\r\n1596000437.invokeStatic_LLL_L(Object, Object, Object, Object) line: not available\r\n504858437.invokeExact_MT(Object, Object, Object, Object, Object) line: not available\r\nFinalScriptFunctionData(ScriptFunctionData).invoke(ScriptFunction, Object, Object...) line: 522\r\nScriptFunctionImpl(ScriptFunction).invoke(Object, Object...) line: 207\r\nScriptRuntime.apply(ScriptFunction, Object, Object...) line: 378\r\nNativeFunction.call(Object, Object...) line: 161\r\n1076496284.invokeStatic_LL_L(Object, Object, Object) line: not available\r\n1740189450.invokeSpecial_LLL_L(Object, Object, Object, Object) line: not available\r\nLambdaForm$NamedFunction.invoke_LLL_L(MethodHandle, Object[]) line: 1113\r\n1076496284.invokeStatic_LL_L(Object, Object, Object) line: not available\r\nLambdaForm$NamedFunction.invokeWithArguments(Object...) line: 1147\r\nLambdaForm.interpretName(LambdaForm$Name, Object[]) line: 625\r\nLambdaForm.interpretWithArguments(Object...) line: 604\r\n2619171.interpret_L(MethodHandle, Object, Object, Object) line: not available\r\nLambdaForm$NamedFunction.invoke_LLL_L(MethodHandle, Object[]) line: 1113\r\n1076496284.invokeStatic_LL_L(Object, Object, Object) line: not available\r\nLambdaForm$NamedFunction.invokeWithArguments(Object...) line: 1147\r\nLambdaForm.interpretName(LambdaForm$Name, Object[]) line: 625\r\nLambdaForm.interpretWithArguments(Object...) line: 604\r\n323326911.interpret_L(MethodHandle, Object, Object, Object, Object) line: not available\r\nLambdaForm$NamedFunction.invoke_LLLL_L(MethodHandle, Object[]) line: 1118\r\n1076496284.invokeStatic_LL_L(Object, Object, Object) line: not available\r\nLambdaForm$NamedFunction.invokeWithArguments(Object...) line: 1147\r\nLambdaForm.interpretName(LambdaForm$Name, Object[]) line: 625\r\nLambdaForm.interpretWithArguments(Object...) line: 604\r\n323326911.interpret_L(MethodHandle, Object, Object, Object, Object) line: not available\r\n263793464.invokeSpecial_LLLLL_L(Object, Object, Object, Object, Object, Object) line: not available\r\nLambdaForm$NamedFunction.invoke_LLLLL_L(MethodHandle, Object[]) line: 1123\r\n1076496284.invokeStatic_LL_L(Object, Object, Object) line: not available\r\nLambdaForm$NamedFunction.invokeWithArguments(Object...) line: 1147\r\nLambdaForm.interpretName(LambdaForm$Name, Object[]) line: 625\r\nLambdaForm.interpretWithArguments(Object...) line: 604\r\n1484673893.interpret_L(MethodHandle, Object, Object, Object, Object, Object) line: not available\r\n587003819.invokeSpecial_LLLLLL_L(Object, Object, Object, Object, Object, Object, Object) line: not available\r\n811301908.invoke_LLLLLL_L(MethodHandle, Object[]) line: not available\r\n1076496284.invokeStatic_LL_L(Object, Object, Object) line: not available\r\nLambdaForm$NamedFunction.invokeWithArguments(Object...) line: 1147\r\nLambdaForm.interpretName(LambdaForm$Name, Object[]) line: 625\r\nLambdaForm.interpretWithArguments(Object...) line: 604\r\n484673893.interpret_L(MethodHandle, Object, Object, Object, Object, Object) line: not available\r\nLambdaForm$NamedFunction.invoke_LLLLL_L(MethodHandle, Object[]) line: 1123\r\n1076496284.invokeStatic_LL_L(Object, Object, Object) line: not available\r\nLambdaForm$NamedFunction.invokeWithArguments(Object...) line: 1147\r\nLambdaForm.interpretName(LambdaForm$Name, Object[]) line: 625\r\nLambdaForm.interpretWithArguments(Object...) line: 604\r\n323326911.interpret_L(MethodHandle, Object, Object, Object, Object) line: not available\r\n2129144075.linkToCallSite(Object, Object, Object, Object, Object) line: not available\r\nScript$\\^eval\\_.runScript(ScriptFunction, Object) line: 3\r\n1076496284.invokeStatic_LL_L(Object, Object, Object) line: not available\r\n1709804316.invokeExact_MT(Object, Object, Object, Object) line: not available\r\nFinalScriptFunctionData(ScriptFunctionData).invoke(ScriptFunction, Object, Object...) line: 498\r\nScriptFunctionImpl(ScriptFunction).invoke(Object, Object...) line: 207\r\nScriptRuntime.apply(ScriptFunction, Object, Object...) line: 378\r\nNashornScriptEngine.evalImpl(ScriptFunction, ScriptContext, ScriptObject) line: 544\r\nNashornScriptEngine.evalImpl(ScriptFunction, ScriptContext) line: 526\r\nNashornScriptEngine.evalImpl(Source, ScriptContext) line: 522\r\nNashornScriptEngine.eval(String, ScriptContext) line: 193\r\nNashornScriptEngine(AbstractScriptEngine).eval(String) line: 264\r\nLmbdaMain.main(String[]) line: 44<\/pre>\n<div class=\"attribution\">\n<table>\n<tbody>\n<tr>\n<td><span class=\"reference\">Reference: <\/span><\/td>\n<td><a href=\"http:\/\/www.takipiblog.com\/2014\/03\/25\/the-dark-side-of-lambda-expressions-in-java-8\/\">The Dark Side Of Lambda Expressions in Java 8<\/a> from our <a href=\"http:\/\/www.javacodegeeks.com\/jcg\">JCG partner<\/a> Tal Weiss at the <a href=\"http:\/\/www.takipiblog.com\/\">Takipi <\/a> blog.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>This post may not make me any new friends. Oh well, I was never really popular at school anyway. But let\u2019s get to the point. Java 8\u2019s biggest feature in terms of the language is undoubtedly Lambda expressions. It\u2019s been a flagship\u00a0feature for functional languages such as Scala and Clojure for a few years, and &hellip;<\/p>\n","protected":false},"author":529,"featured_media":148,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[196,197],"class_list":["post-23423","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-core-java","tag-java-8","tag-lambdas"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>The Dark Side Of Lambda Expressions in Java 8<\/title>\n<meta name=\"description\" content=\"This post may not make me any new friends. Oh well, I was never really popular at school anyway. But let\u2019s get to the point. Java 8\u2019s biggest feature in\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.javacodegeeks.com\/2014\/03\/the-dark-side-of-lambda-expressions-in-java-8.html\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"The Dark Side Of Lambda Expressions in Java 8\" \/>\n<meta property=\"og:description\" content=\"This post may not make me any new friends. Oh well, I was never really popular at school anyway. But let\u2019s get to the point. Java 8\u2019s biggest feature in\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.javacodegeeks.com\/2014\/03\/the-dark-side-of-lambda-expressions-in-java-8.html\" \/>\n<meta property=\"og:site_name\" content=\"Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2014-03-30T22:00:32+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2014-04-03T09:13:54+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/java-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Tal Weiss\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Tal Weiss\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"11 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/03\\\/the-dark-side-of-lambda-expressions-in-java-8.html#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/03\\\/the-dark-side-of-lambda-expressions-in-java-8.html\"},\"author\":{\"name\":\"Tal Weiss\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/2dc6b8e5a433ff29fcdf2167aedc3d57\"},\"headline\":\"The Dark Side Of Lambda Expressions in Java 8\",\"datePublished\":\"2014-03-30T22:00:32+00:00\",\"dateModified\":\"2014-04-03T09:13:54+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/03\\\/the-dark-side-of-lambda-expressions-in-java-8.html\"},\"wordCount\":953,\"commentCount\":21,\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/03\\\/the-dark-side-of-lambda-expressions-in-java-8.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/java-logo.jpg\",\"keywords\":[\"Java 8\",\"Lambdas\"],\"articleSection\":[\"Core Java\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/03\\\/the-dark-side-of-lambda-expressions-in-java-8.html#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/03\\\/the-dark-side-of-lambda-expressions-in-java-8.html\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/03\\\/the-dark-side-of-lambda-expressions-in-java-8.html\",\"name\":\"The Dark Side Of Lambda Expressions in Java 8\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/03\\\/the-dark-side-of-lambda-expressions-in-java-8.html#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/03\\\/the-dark-side-of-lambda-expressions-in-java-8.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/java-logo.jpg\",\"datePublished\":\"2014-03-30T22:00:32+00:00\",\"dateModified\":\"2014-04-03T09:13:54+00:00\",\"description\":\"This post may not make me any new friends. Oh well, I was never really popular at school anyway. But let\u2019s get to the point. Java 8\u2019s biggest feature in\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/03\\\/the-dark-side-of-lambda-expressions-in-java-8.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/03\\\/the-dark-side-of-lambda-expressions-in-java-8.html\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/03\\\/the-dark-side-of-lambda-expressions-in-java-8.html#primaryimage\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/java-logo.jpg\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/java-logo.jpg\",\"width\":150,\"height\":150},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/03\\\/the-dark-side-of-lambda-expressions-in-java-8.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/java\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Core Java\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/java\\\/core-java\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"The Dark Side Of Lambda Expressions in Java 8\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Developers Resource Center\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.javacodegeeks.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/javacodegeeks\",\"https:\\\/\\\/x.com\\\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/2dc6b8e5a433ff29fcdf2167aedc3d57\",\"name\":\"Tal Weiss\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/e70d5bd7ae7a7a580e9fc6ee8f21e204f382b27e2e9eb52338e644f1704429b1?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/e70d5bd7ae7a7a580e9fc6ee8f21e204f382b27e2e9eb52338e644f1704429b1?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/e70d5bd7ae7a7a580e9fc6ee8f21e204f382b27e2e9eb52338e644f1704429b1?s=96&d=mm&r=g\",\"caption\":\"Tal Weiss\"},\"description\":\"Tal is co-founder and CEO at Takipi where he leads a team of hackers that build tools that help fix Java and Scala code in production. His main interests are tools for developers, solving nasty bugs (preferably multi-threaded) and Jazz drumming.\",\"sameAs\":[\"http:\\\/\\\/www.takipi.com\\\/\"],\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/author\\\/tal-weiss\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"The Dark Side Of Lambda Expressions in Java 8","description":"This post may not make me any new friends. Oh well, I was never really popular at school anyway. But let\u2019s get to the point. Java 8\u2019s biggest feature in","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.javacodegeeks.com\/2014\/03\/the-dark-side-of-lambda-expressions-in-java-8.html","og_locale":"en_US","og_type":"article","og_title":"The Dark Side Of Lambda Expressions in Java 8","og_description":"This post may not make me any new friends. Oh well, I was never really popular at school anyway. But let\u2019s get to the point. Java 8\u2019s biggest feature in","og_url":"https:\/\/www.javacodegeeks.com\/2014\/03\/the-dark-side-of-lambda-expressions-in-java-8.html","og_site_name":"Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2014-03-30T22:00:32+00:00","article_modified_time":"2014-04-03T09:13:54+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/java-logo.jpg","type":"image\/jpeg"}],"author":"Tal Weiss","twitter_card":"summary_large_image","twitter_creator":"@javacodegeeks","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Tal Weiss","Est. reading time":"11 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.javacodegeeks.com\/2014\/03\/the-dark-side-of-lambda-expressions-in-java-8.html#article","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/2014\/03\/the-dark-side-of-lambda-expressions-in-java-8.html"},"author":{"name":"Tal Weiss","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/2dc6b8e5a433ff29fcdf2167aedc3d57"},"headline":"The Dark Side Of Lambda Expressions in Java 8","datePublished":"2014-03-30T22:00:32+00:00","dateModified":"2014-04-03T09:13:54+00:00","mainEntityOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2014\/03\/the-dark-side-of-lambda-expressions-in-java-8.html"},"wordCount":953,"commentCount":21,"publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2014\/03\/the-dark-side-of-lambda-expressions-in-java-8.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/java-logo.jpg","keywords":["Java 8","Lambdas"],"articleSection":["Core Java"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.javacodegeeks.com\/2014\/03\/the-dark-side-of-lambda-expressions-in-java-8.html#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.javacodegeeks.com\/2014\/03\/the-dark-side-of-lambda-expressions-in-java-8.html","url":"https:\/\/www.javacodegeeks.com\/2014\/03\/the-dark-side-of-lambda-expressions-in-java-8.html","name":"The Dark Side Of Lambda Expressions in Java 8","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2014\/03\/the-dark-side-of-lambda-expressions-in-java-8.html#primaryimage"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2014\/03\/the-dark-side-of-lambda-expressions-in-java-8.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/java-logo.jpg","datePublished":"2014-03-30T22:00:32+00:00","dateModified":"2014-04-03T09:13:54+00:00","description":"This post may not make me any new friends. Oh well, I was never really popular at school anyway. But let\u2019s get to the point. Java 8\u2019s biggest feature in","breadcrumb":{"@id":"https:\/\/www.javacodegeeks.com\/2014\/03\/the-dark-side-of-lambda-expressions-in-java-8.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.javacodegeeks.com\/2014\/03\/the-dark-side-of-lambda-expressions-in-java-8.html"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/2014\/03\/the-dark-side-of-lambda-expressions-in-java-8.html#primaryimage","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/java-logo.jpg","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/java-logo.jpg","width":150,"height":150},{"@type":"BreadcrumbList","@id":"https:\/\/www.javacodegeeks.com\/2014\/03\/the-dark-side-of-lambda-expressions-in-java-8.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Java","item":"https:\/\/www.javacodegeeks.com\/category\/java"},{"@type":"ListItem","position":3,"name":"Core Java","item":"https:\/\/www.javacodegeeks.com\/category\/java\/core-java"},{"@type":"ListItem","position":4,"name":"The Dark Side Of Lambda Expressions in Java 8"}]},{"@type":"WebSite","@id":"https:\/\/www.javacodegeeks.com\/#website","url":"https:\/\/www.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Developers Resource Center","publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/www.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/2dc6b8e5a433ff29fcdf2167aedc3d57","name":"Tal Weiss","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/e70d5bd7ae7a7a580e9fc6ee8f21e204f382b27e2e9eb52338e644f1704429b1?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/e70d5bd7ae7a7a580e9fc6ee8f21e204f382b27e2e9eb52338e644f1704429b1?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/e70d5bd7ae7a7a580e9fc6ee8f21e204f382b27e2e9eb52338e644f1704429b1?s=96&d=mm&r=g","caption":"Tal Weiss"},"description":"Tal is co-founder and CEO at Takipi where he leads a team of hackers that build tools that help fix Java and Scala code in production. His main interests are tools for developers, solving nasty bugs (preferably multi-threaded) and Jazz drumming.","sameAs":["http:\/\/www.takipi.com\/"],"url":"https:\/\/www.javacodegeeks.com\/author\/tal-weiss"}]}},"_links":{"self":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/23423","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/users\/529"}],"replies":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=23423"}],"version-history":[{"count":0,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/23423\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media\/148"}],"wp:attachment":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=23423"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=23423"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=23423"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}