{"id":322,"date":"2022-04-09T16:55:51","date_gmt":"2022-04-09T08:55:51","guid":{"rendered":"https:\/\/blog.lijiajia.top\/?p=322"},"modified":"2026-06-19T21:59:11","modified_gmt":"2026-06-19T13:59:11","slug":"java-lambda-%e8%a1%a8%e8%be%be%e5%bc%8f","status":"publish","type":"post","link":"https:\/\/blog.ttwow.top\/?p=322","title":{"rendered":"Java-Lambda-\u8868\u8fbe\u5f0f"},"content":{"rendered":"<p>\u8f6c\u8f7d\uff1a<a href=\"https:\/\/www.runoob.com\/java\/java8-lambda-expressions.html\">https:\/\/www.runoob.com\/java\/java8-lambda-expressions.html<\/a><\/p>\n<p>Lambda \u8868\u8fbe\u5f0f\uff0c\u4e5f\u53ef\u79f0\u4e3a\u95ed\u5305\uff0c\u5b83\u662f\u63a8\u52a8 Java 8 \u53d1\u5e03\u7684\u6700\u91cd\u8981\u65b0\u7279\u6027\u3002<\/p>\n<p>Lambda \u5141\u8bb8\u628a\u51fd\u6570\u4f5c\u4e3a\u4e00\u4e2a\u65b9\u6cd5\u7684\u53c2\u6570\uff08\u51fd\u6570\u4f5c\u4e3a\u53c2\u6570\u4f20\u9012\u8fdb\u65b9\u6cd5\u4e2d\uff09\u3002<\/p>\n<p>\u4f7f\u7528 Lambda \u8868\u8fbe\u5f0f\u53ef\u4ee5\u4f7f\u4ee3\u7801\u53d8\u7684\u66f4\u52a0\u7b80\u6d01\u7d27\u51d1\u3002<\/p>\n<p>\u8bed\u6cd5<br \/>\nlambda \u8868\u8fbe\u5f0f\u7684\u8bed\u6cd5\u683c\u5f0f\u5982\u4e0b\uff1a<\/p>\n<pre><code>(parameters) -&gt; expression\n\u6216\n(parameters) -&gt;{ statements; }\n<\/code><\/pre>\n<p>\u4ee5\u4e0b\u662flambda\u8868\u8fbe\u5f0f\u7684\u91cd\u8981\u7279\u5f81:<\/p>\n<p>\u53ef\u9009\u7c7b\u578b\u58f0\u660e\uff1a\u4e0d\u9700\u8981\u58f0\u660e\u53c2\u6570\u7c7b\u578b\uff0c\u7f16\u8bd1\u5668\u53ef\u4ee5\u7edf\u4e00\u8bc6\u522b\u53c2\u6570\u503c\u3002<br \/>\n\u53ef\u9009\u7684\u53c2\u6570\u5706\u62ec\u53f7\uff1a\u4e00\u4e2a\u53c2\u6570\u65e0\u9700\u5b9a\u4e49\u5706\u62ec\u53f7\uff0c\u4f46\u591a\u4e2a\u53c2\u6570\u9700\u8981\u5b9a\u4e49\u5706\u62ec\u53f7\u3002<br \/>\n\u53ef\u9009\u7684\u5927\u62ec\u53f7\uff1a\u5982\u679c\u4e3b\u4f53\u5305\u542b\u4e86\u4e00\u4e2a\u8bed\u53e5\uff0c\u5c31\u4e0d\u9700\u8981\u4f7f\u7528\u5927\u62ec\u53f7\u3002<br \/>\n\u53ef\u9009\u7684\u8fd4\u56de\u5173\u952e\u5b57\uff1a\u5982\u679c\u4e3b\u4f53\u53ea\u6709\u4e00\u4e2a\u8868\u8fbe\u5f0f\u8fd4\u56de\u503c\u5219\u7f16\u8bd1\u5668\u4f1a\u81ea\u52a8\u8fd4\u56de\u503c\uff0c\u5927\u62ec\u53f7\u9700\u8981\u6307\u5b9a\u8868\u8fbe\u5f0f\u8fd4\u56de\u4e86\u4e00\u4e2a\u6570\u503c\u3002<\/p>\n<p>Lambda \u8868\u8fbe\u5f0f\u5b9e\u4f8b<br \/>\nLambda \u8868\u8fbe\u5f0f\u7684\u7b80\u5355\u4f8b\u5b50:<\/p>\n<pre><code>\/\/ 1. \u4e0d\u9700\u8981\u53c2\u6570,\u8fd4\u56de\u503c\u4e3a 5\n() -&gt; 5\n\n\/\/ 2. \u63a5\u6536\u4e00\u4e2a\u53c2\u6570(\u6570\u5b57\u7c7b\u578b),\u8fd4\u56de\u51762\u500d\u7684\u503c\nx -&gt; 2 * x\n\n\/\/ 3. \u63a5\u53d72\u4e2a\u53c2\u6570(\u6570\u5b57),\u5e76\u8fd4\u56de\u4ed6\u4eec\u7684\u5dee\u503c\n(x, y) -&gt; x \u2013 y\n\n\/\/ 4. \u63a5\u65362\u4e2aint\u578b\u6574\u6570,\u8fd4\u56de\u4ed6\u4eec\u7684\u548c\n(int x, int y) -&gt; x + y\n\n\/\/ 5. \u63a5\u53d7\u4e00\u4e2a string \u5bf9\u8c61,\u5e76\u5728\u63a7\u5236\u53f0\u6253\u5370,\u4e0d\u8fd4\u56de\u4efb\u4f55\u503c(\u770b\u8d77\u6765\u50cf\u662f\u8fd4\u56devoid)\n(String s) -&gt; System.out.print(s)<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u8f6c\u8f7d\uff1ahttps:\/\/www.runoob.com\/java\/java8-lambda-expressions [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[125],"tags":[50],"class_list":["post-322","post","type-post","status-publish","format-standard","hentry","category-java-backend","tag-lambda"],"_links":{"self":[{"href":"https:\/\/blog.ttwow.top\/index.php?rest_route=\/wp\/v2\/posts\/322","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.ttwow.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.ttwow.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.ttwow.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.ttwow.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=322"}],"version-history":[{"count":1,"href":"https:\/\/blog.ttwow.top\/index.php?rest_route=\/wp\/v2\/posts\/322\/revisions"}],"predecessor-version":[{"id":2198,"href":"https:\/\/blog.ttwow.top\/index.php?rest_route=\/wp\/v2\/posts\/322\/revisions\/2198"}],"wp:attachment":[{"href":"https:\/\/blog.ttwow.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=322"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.ttwow.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=322"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.ttwow.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=322"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}