{"id":4197,"date":"2014-03-30T09:12:12","date_gmt":"2014-03-30T09:12:12","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/java-sam-type-optimization-collection-of-common-programming-errors\/"},"modified":"2014-03-30T09:12:12","modified_gmt":"2014-03-30T09:12:12","slug":"java-sam-type-optimization-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/java-sam-type-optimization-collection-of-common-programming-errors\/","title":{"rendered":"Java &#8211; SAM type optimization-Collection of common programming errors"},"content":{"rendered":"<p>@Tam\u00e1s You should probably have a read of this mailing list post by Brian Goetz:<\/p>\n<p>http:\/\/mail.openjdk.java.net\/pipermail\/lambda-dev\/2011-August\/003877.html<\/p>\n<p>Basically, the lambda abstraction is currently implemented using objects. However, it has been designed to permit alternative realizations of lambdas, which would be &#8220;smaller&#8221; than instances of classes.<\/p>\n<p>You can think of the situation as similar to autoboxing &#8211; ints are boxed to Integer, but have a &#8220;smaller&#8221; representation (as ints).<\/p>\n<p>Currently, lambdas have to be boxed to instances of SAM types, b\/c the JVM currently has no way to represent a lambda with any smaller construct. In the future, there may be a new JVM standard which includes &#8220;primitive functions&#8221; which could represent lambdas as something other than objects.<\/p>\n<p>So, to answer your question, the type of optimization you propose above, may be possible, but it probably would come with post-Java 8 work on &#8220;primitive functions&#8221; rather than being an implementation-specific feature.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>@Tam\u00e1s You should probably have a read of this mailing list post by Brian Goetz: http:\/\/mail.openjdk.java.net\/pipermail\/lambda-dev\/2011-August\/003877.html Basically, the lambda abstraction is currently implemented using objects. However, it has been designed to permit alternative realizations of lambdas, which would be &#8220;smaller&#8221; than instances of classes. You can think of the situation as similar to autoboxing &#8211; [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-4197","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/4197","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=4197"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/4197\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=4197"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=4197"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=4197"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}