{"id":20787,"date":"2014-01-24T13:00:49","date_gmt":"2014-01-24T11:00:49","guid":{"rendered":"http:\/\/www.javacodegeeks.com\/?p=20787"},"modified":"2014-01-24T10:59:16","modified_gmt":"2014-01-24T08:59:16","slug":"compiling-lambda-expressions-scala-vs-java-8","status":"publish","type":"post","link":"https:\/\/www.javacodegeeks.com\/2014\/01\/compiling-lambda-expressions-scala-vs-java-8.html","title":{"rendered":"Compiling Lambda Expressions: Scala vs. Java 8"},"content":{"rendered":"<p>Lambda expressions have taken the programming world by storm in the last few years. Most modern languages have adopted them as a fundamental part of functional programming. JVM based languages such as Scala, Groovy and Clojure have integrated them as key part of the language. And now, Java 8 is (finally) joining in on the fun.<\/p>\n<p><a href=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2014\/01\/lambda.jpg\"><img decoding=\"async\" class=\"alignright size-medium wp-image-21004\" alt=\"lambda\" src=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2014\/01\/lambda-300x155.jpg\" width=\"300\" height=\"155\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2014\/01\/lambda-300x155.jpg 300w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2014\/01\/lambda.jpg 580w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a>What\u2019s interesting about Lambda expressions is that from the JVM\u2019s perspective they\u2019re completely invisible. It has no notion of what an anonymous function or a Lambda expression is. It only knows bytecode which is a strict OO specification. It\u2019s up to the makers of the language and its compiler to work within these constraints to create newer, more advanced language elements.<\/p>\n<p>We first encountered this when we were working on adding Scala support to <a href=\"http:\/\/www.takipi.com\" target=\"_blank\">Takipi<\/a> and had to dive deep into the Scala compiler. With Java 8 right around the corner, I thought it would be interesting to see how the Scala and Java compilers implement Lambda expressions. The results were pretty surprising.<\/p>\n<p>To get things going I took a simple Lambda expression that converts a list of Strings to a list of their lengths.<\/p>\n<p>In Java &#8211;<\/p>\n<pre class=\" brush:java\">List names = Arrays.asList(\"1\", \"2\", \"3\");\r\nStream lengths = names.stream().map(name -&gt; name.length());<\/pre>\n<p>In Scala &#8211;<\/p>\n<pre class=\" brush:scala\">val names = List(\"1\", \"2\", \"3\")\r\nval lengths = names.map(name =&gt; name.length)<\/pre>\n<p>Don\u2019t be tricked its simplicity \u2013 behind the scenes some complex stuff is going on.<\/p>\n<h2>Let\u2019s start with Scala<\/h2>\n<p><a href=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2014\/01\/SCalaLam-1.jpg\"><img decoding=\"async\" class=\"aligncenter size-full wp-image-21005\" alt=\"SCalaLam-1\" src=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2014\/01\/SCalaLam-1.jpg\" width=\"233\" height=\"222\" \/><\/a><\/p>\n<h4>The Code<\/h4>\n<p>I used javap to view the bytecode contents of the .class produced by the Scala compiler. Let\u2019s look at the result bytecode (this is what the JVM will actually execute).<\/p>\n<pre class=\" brush:scala\">\/\/ this loads the names var into the stack (the JVM thinks\r\n\/\/ of it as variable #2).\r\n\/\/ It\u2019s going to stay there for a while till it gets used\r\n\/\/ by the &lt;em&gt;.map&lt;\/em&gt; function.\r\n\r\naload_2<\/pre>\n<p>Next, things gets more interesting \u2013 a new instance of a synthetic class generated by the compiler is created and initialized. This is the object that from the JVM\u2019s perspective holds the Lambda method. It\u2019s funny that while the Lambda is defined as an integral part of our method, in reality it lives completely outside of our class.<\/p>\n<pre class=\" brush:scala\">new myLambdas\/Lambda1$$anonfun$1 \/\/instantiate the Lambda object\r\ndup \/\/put it into the stack again\r\n\r\n\/\/ finally, invoke the c\u2019tor. Remember - it\u2019s just a plain object\r\n\/\/ from the JVM\u2019s perspective.\r\ninvokespecial myLambdas\/Lambda1$$anonfun$1\/()V\r\n\r\n\/\/ these two (long) lines loads the immutable.List CanBuildFrom factory\r\n\/\/ which will create the new list. This factory pattern is a part of\r\n\/\/ Scala\u2019s collections architecture\r\ngetstatic scala\/collection\/immutable\/List$\/MODULE$\r\nLscala\/collection\/immutable\/List$;\r\ninvokevirtual scala\/collection\/immutable\/List$\/canBuildFrom()\r\nLscala\/collection\/generic\/CanBuildFrom;\r\n\r\n\/\/ Now we have on the stack the Lambda object and the factory.\r\n\/\/ The next phase is to call the .&lt;em&gt;map&lt;\/em&gt;() function. \r\n\/\/ If you remember, we loaded the &lt;em&gt;names&lt;\/em&gt; var onto \r\n\/\/ the stack in the beginning. Now it\u2019ll gets used as the \r\n\/\/ this for the .&lt;em&gt;map&lt;\/em&gt;() call, which will also \r\n\/\/ accept the Lambda object and the factory to produce the \r\n\/\/ new list of lengths.\r\n\r\ninvokevirtual scala\/collection\/immutable\/List\/map(Lscala\/Function1;\r\nLscala\/collection\/generic\/CanBuildFrom;)Ljava\/lang\/Object;<\/pre>\n<p>But hold on \u2013 what\u2019s going on inside that Lambda object?<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<h4>The Lambda object<\/h4>\n<p>The Lambda class is derived from <em>scala.runtime.AbstractFunction1<\/em>. Through this the <em>map<\/em>() function can polymorphically invoke the overridden apply() whose code is below &#8211;<\/p>\n<pre class=\" brush:scala\">\/\/ this code loads this and the target object on which to act,\r\n\/\/ checks that it\u2019s a String, and then calls another apply overload\r\n\/\/ to do the actual work and boxes its return value.\r\naload_0 \/\/load this\r\naload_1 \/\/load the string arg\r\ncheckcast java\/lang\/String \/\/make sure it\u2019s a String - we got an Object\r\n\r\n\/\/ call another apply() method in the synthetic class\r\ninvokevirtual myLambdas\/Lambda1$$anonfun$1\/apply(Ljava\/lang\/String;)I\r\n\r\n\/\/box the result\r\ninvokestatic scala\/runtime\/BoxesRunTime\/boxToInteger(I)Ljava\/lang\/Integer\r\nareturn<\/pre>\n<p>The actual code to perform the .<em>length<\/em>() operation is nested in that additional apply method which simply returns the length of the String as we expected.<\/p>\n<p>Phew.. it was quite a long way to get here!<\/p>\n<pre class=\" brush:scala\">aload_1\r\ninvokevirtual java\/lang\/String\/length()I\r\nireturn<\/pre>\n<p>For a line as simple as we write above, quite a lot of bytecode is generated \u2013 an additional class and a bunch of new methods. This of course isn\u2019t meant to dissuade us from using Lambdas (we\u2019re writing in Scala, not C). It just goes to show the complexity behind these constructs. Just think of the amount of code and complexity that goes into compiling complex chains of Lambda expressions!<\/p>\n<p>I was quite expecting Java 8 to implement this the same way, but was quite surprised to see that they took another approach completely.<\/p>\n<h2>Java 8 \u2013 A new approach<\/h2>\n<p><a href=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2014\/01\/JavaLam-1.jpg\"><img decoding=\"async\" class=\"aligncenter size-full wp-image-21006\" alt=\"JavaLam-1\" src=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2014\/01\/JavaLam-1.jpg\" width=\"230\" height=\"229\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2014\/01\/JavaLam-1.jpg 230w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2014\/01\/JavaLam-1-150x150.jpg 150w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2014\/01\/JavaLam-1-200x200.jpg 200w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2014\/01\/JavaLam-1-100x100.jpg 100w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2014\/01\/JavaLam-1-42x42.jpg 42w\" sizes=\"(max-width: 230px) 100vw, 230px\" \/><\/a><\/p>\n<p>The bytecode here is a bit shorter but does something rather surprising. It begins quite simply by loading the <em>names<\/em> var and invokes its .<em>stream<\/em>() method, but then it does something quite elegant. Instead of creating a new object that will wrap the Lambda function, it uses the new <em>invokeDynamic<\/em> instruction which was added in Java 7 to dynamically link this call site to the actual Lambda function.<\/p>\n<pre class=\" brush:java\">aload_1 \/\/load the names var\r\n\r\n\/\/ call its stream() func\r\ninvokeinterface java\/util\/List.stream:()Ljava\/util\/stream\/Stream;\r\n\r\n\/\/invokeDynamic magic!\r\ninvokedynamic #0:apply:()Ljava\/util\/function\/Function;\r\n\r\n\/\/call the map() func\r\ninvokeinterface java\/util\/stream\/Stream.map:\r\n(Ljava\/util\/function\/Function;)Ljava\/util\/stream\/Stream;<\/pre>\n<p><strong>InvokeDynamic magic<\/strong>. This JVM instruction was added in Java 7 to make the JVM less strict, and allows dynamic languages to bind symbols at run-time, vs. doing all the linkage statically when the code is compiled by the JVM.<\/p>\n<p><strong>Dynamic Linking<\/strong>. If you look at the actual <em>invokedynamic<\/em> instruction you\u2019ll see there\u2019s no reference of the actual Lambda function (called lambda$0). The answer lies in the way invokedynamic is designed (which in itself deserves a full post), but the short answer is the name and signature of the Lambda, which in our case is &#8211;<\/p>\n<pre class=\" brush:java\">\/\/ a function named lamda$0 that gets a String and returns an Integer\r\nlambdas\/Lambda1.lambda$0:(Ljava\/lang\/String;)Ljava\/lang\/Integer;<\/pre>\n<p>are stored in an entry in a separate table in the .class to which the #0 parameter passed to the instruction points. This new table actually changed the structure of the bytecode specification for the first time after a good few years, requiring us to adapt <a href=\"http:\/\/www.takipi.com\" target=\"_blank\">Takipi\u2019s<\/a> error analysis engine to it as well.<\/p>\n<h4>The Lambda code<\/h4>\n<p>This is the code for the actual Lambda\u00a0expression. It\u2019s very cookie-cutter \u2013 simply load the String parameter, call <em>length<\/em>() and box the result. Notice it was compiled as a <em>static<\/em> function to avoid having to pass an additional <em>this<\/em> object to it like we saw in Scala.<\/p>\n<pre class=\" brush:java\">aload_0\r\ninvokevirtual java\/lang\/String.length:()\r\ninvokestatic java\/lang\/Integer.valueOf:(I)Ljava\/lang\/Integer;\r\nareturn<\/pre>\n<p>This is another advantage of the <em>invokedynamic<\/em> approach, as it allows us to invoke the method in a way which is polymorphic from the .map() function\u2019s perspective, but without having to allocate a wrapper object or invoke a virtual override method. Pretty cool!<\/p>\n<h2>Summary<\/h2>\n<p>It\u2019s fascinating to see how Java, the most \u201cstrict\u201d of modern languages is now using dynamic linkage to power its new Lambda expressions. It\u2019s also an efficient approach, as no additional class loading and compilation is needed \u2013 the Lambda method is simply another private method in our class.<\/p>\n<p>Java 8 has really done a very elegant job in using new technology introduced in Java 7 to implement Lambda expressions in what is a very straightforward way. It\u2019s pleasant in a way to see that even a \u201cvenerable\u201d lady such as Java can teach us all some new tricks<br \/>\n&nbsp;<\/p>\n<div style=\"border: 1px solid #D8D8D8; background: #FAFAFA; width: 100%; padding-left: 5px;\"><b><i>Reference: <\/i><\/b><a href=\"http:\/\/www.takipiblog.com\/2014\/01\/16\/compiling-lambda-expressions-scala-vs-java-8\/\">Compiling Lambda Expressions: Scala vs. 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.<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Lambda expressions have taken the programming world by storm in the last few years. Most modern languages have adopted them as a fundamental part of functional programming. JVM based languages such as Scala, Groovy and Clojure have integrated them as key part of the language. And now, Java 8 is (finally) joining in on the &hellip;<\/p>\n","protected":false},"author":529,"featured_media":227,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[20],"tags":[197],"class_list":["post-20787","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scala","tag-lambdas"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Compiling Lambda Expressions: Scala vs. Java 8<\/title>\n<meta name=\"description\" content=\"Lambda expressions have taken the programming world by storm in the last few years. Most modern languages have adopted them as a fundamental part of\" \/>\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\/01\/compiling-lambda-expressions-scala-vs-java-8.html\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Compiling Lambda Expressions: Scala vs. Java 8\" \/>\n<meta property=\"og:description\" content=\"Lambda expressions have taken the programming world by storm in the last few years. Most modern languages have adopted them as a fundamental part of\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.javacodegeeks.com\/2014\/01\/compiling-lambda-expressions-scala-vs-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-01-24T11:00:49+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/scala-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=\"7 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/01\\\/compiling-lambda-expressions-scala-vs-java-8.html#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/01\\\/compiling-lambda-expressions-scala-vs-java-8.html\"},\"author\":{\"name\":\"Tal Weiss\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/2dc6b8e5a433ff29fcdf2167aedc3d57\"},\"headline\":\"Compiling Lambda Expressions: Scala vs. Java 8\",\"datePublished\":\"2014-01-24T11:00:49+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/01\\\/compiling-lambda-expressions-scala-vs-java-8.html\"},\"wordCount\":921,\"commentCount\":3,\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/01\\\/compiling-lambda-expressions-scala-vs-java-8.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/scala-logo.jpg\",\"keywords\":[\"Lambdas\"],\"articleSection\":[\"Scala\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/01\\\/compiling-lambda-expressions-scala-vs-java-8.html#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/01\\\/compiling-lambda-expressions-scala-vs-java-8.html\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/01\\\/compiling-lambda-expressions-scala-vs-java-8.html\",\"name\":\"Compiling Lambda Expressions: Scala vs. Java 8\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/01\\\/compiling-lambda-expressions-scala-vs-java-8.html#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/01\\\/compiling-lambda-expressions-scala-vs-java-8.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/scala-logo.jpg\",\"datePublished\":\"2014-01-24T11:00:49+00:00\",\"description\":\"Lambda expressions have taken the programming world by storm in the last few years. Most modern languages have adopted them as a fundamental part of\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/01\\\/compiling-lambda-expressions-scala-vs-java-8.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/01\\\/compiling-lambda-expressions-scala-vs-java-8.html\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/01\\\/compiling-lambda-expressions-scala-vs-java-8.html#primaryimage\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/scala-logo.jpg\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/scala-logo.jpg\",\"width\":150,\"height\":150},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/01\\\/compiling-lambda-expressions-scala-vs-java-8.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"JVM Languages\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/jvm-languages\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Scala\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/jvm-languages\\\/scala\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Compiling Lambda Expressions: Scala vs. 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":"Compiling Lambda Expressions: Scala vs. Java 8","description":"Lambda expressions have taken the programming world by storm in the last few years. Most modern languages have adopted them as a fundamental part of","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\/01\/compiling-lambda-expressions-scala-vs-java-8.html","og_locale":"en_US","og_type":"article","og_title":"Compiling Lambda Expressions: Scala vs. Java 8","og_description":"Lambda expressions have taken the programming world by storm in the last few years. Most modern languages have adopted them as a fundamental part of","og_url":"https:\/\/www.javacodegeeks.com\/2014\/01\/compiling-lambda-expressions-scala-vs-java-8.html","og_site_name":"Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2014-01-24T11:00:49+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/scala-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":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.javacodegeeks.com\/2014\/01\/compiling-lambda-expressions-scala-vs-java-8.html#article","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/2014\/01\/compiling-lambda-expressions-scala-vs-java-8.html"},"author":{"name":"Tal Weiss","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/2dc6b8e5a433ff29fcdf2167aedc3d57"},"headline":"Compiling Lambda Expressions: Scala vs. Java 8","datePublished":"2014-01-24T11:00:49+00:00","mainEntityOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2014\/01\/compiling-lambda-expressions-scala-vs-java-8.html"},"wordCount":921,"commentCount":3,"publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2014\/01\/compiling-lambda-expressions-scala-vs-java-8.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/scala-logo.jpg","keywords":["Lambdas"],"articleSection":["Scala"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.javacodegeeks.com\/2014\/01\/compiling-lambda-expressions-scala-vs-java-8.html#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.javacodegeeks.com\/2014\/01\/compiling-lambda-expressions-scala-vs-java-8.html","url":"https:\/\/www.javacodegeeks.com\/2014\/01\/compiling-lambda-expressions-scala-vs-java-8.html","name":"Compiling Lambda Expressions: Scala vs. Java 8","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2014\/01\/compiling-lambda-expressions-scala-vs-java-8.html#primaryimage"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2014\/01\/compiling-lambda-expressions-scala-vs-java-8.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/scala-logo.jpg","datePublished":"2014-01-24T11:00:49+00:00","description":"Lambda expressions have taken the programming world by storm in the last few years. Most modern languages have adopted them as a fundamental part of","breadcrumb":{"@id":"https:\/\/www.javacodegeeks.com\/2014\/01\/compiling-lambda-expressions-scala-vs-java-8.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.javacodegeeks.com\/2014\/01\/compiling-lambda-expressions-scala-vs-java-8.html"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/2014\/01\/compiling-lambda-expressions-scala-vs-java-8.html#primaryimage","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/scala-logo.jpg","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/scala-logo.jpg","width":150,"height":150},{"@type":"BreadcrumbList","@id":"https:\/\/www.javacodegeeks.com\/2014\/01\/compiling-lambda-expressions-scala-vs-java-8.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"JVM Languages","item":"https:\/\/www.javacodegeeks.com\/category\/jvm-languages"},{"@type":"ListItem","position":3,"name":"Scala","item":"https:\/\/www.javacodegeeks.com\/category\/jvm-languages\/scala"},{"@type":"ListItem","position":4,"name":"Compiling Lambda Expressions: Scala vs. 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\/20787","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=20787"}],"version-history":[{"count":0,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/20787\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media\/227"}],"wp:attachment":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=20787"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=20787"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=20787"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}