{"id":6676,"date":"2022-07-28T11:24:11","date_gmt":"2022-07-28T03:24:11","guid":{"rendered":"http:\/\/123.57.164.21\/?p=6676"},"modified":"2022-07-28T20:29:53","modified_gmt":"2022-07-28T12:29:53","slug":"%e8%af%a6%e8%a7%a3java%e4%b8%ad%e7%9a%84lambda%e8%a1%a8%e8%be%be%e5%bc%8f","status":"publish","type":"post","link":"https:\/\/92it.top\/?p=6676","title":{"rendered":"\u8be6\u89e3Java\u4e2d\u7684Lambda\u8868\u8fbe\u5f0f(\u63a8\u8350)"},"content":{"rendered":"\n<p>Java \u76ee\u524d\u5df2\u7ecf\u51fa\u523013\u7684\u7248\u672c\uff0c\u4f46\u662f\u56fd\u5185\u5927\u90e8\u5206\u516c\u53f8\u5e94\u8be5\u90fd\u505c\u7559\u5728 Java 8 \u7684\u7248\u672c\uff08\u4e0d\u6562\u627f\u62c5\u5347\u7ea7\u5e26\u6765\u7684\u98ce\u9669\uff09\u3002\u5728Java8\u4e2d\u7ed9\u6211\u4eec\u5e26\u6765\u4e86 Lambda\u8868\u8fbe\u5f0f\u548cStream\u6d41\u5f0f\u64cd\u4f5c\uff0c\u63d0\u4f9b\u4e86\u51fd\u6570\u5f0f\u7f16\u7a0b\u548c\u7b80\u5316\u6279\u5904\u7406\u64cd\u4f5c\u3002\u53ef\u80fd\u5927\u5bb6\u65e5\u5e38\u4f7f\u7528\u5f88\u591a\uff0c\u4f46\u662f\u5f88\u5c11\u53bb\u5173\u6ce8Lambda \u548c Stream\u5b9e\u73b0\u3002\u672c\u7bc7\u5c31\u5e26\u7740\u5927\u5bb6\u4e00\u8d77\u5173\u6ce8\u8fd9\u4e24\u5757\u77e5\u8bc6\uff0c\u642c\u597d\u5c0f\u677f\u51f3\u6211\u4eec\u4e00\u8d77\u770b\u7535\u89c6\u3002<\/p>\n\n\n\n<p>\u5728java\u4e2d\u6211\u4eec\u5f88\u5bb9\u6613\u5c06\u4e00\u4e2a\u53d8\u91cf\u8d4b\u503c\uff0c\u6bd4\u5982int a =0;int b=a;<\/p>\n\n\n\n<p>\u4f46\u662f\u6211\u4eec\u5982\u4f55\u5c06\u4e00\u6bb5\u4ee3\u7801\u548c\u4e00\u4e2a\u51fd\u6570\u8d4b\u503c\u7ed9\u4e00\u4e2a\u53d8\u91cf\uff1f\u8fd9\u4e2a\u53d8\u91cf\u5e94\u8be5\u662f\u4ec0\u4e48\u7684\u7c7b\u578b\uff1f<\/p>\n\n\n\n<p>\u5728javascript\u4e2d\uff0c\u53ef\u4ee5\u7528\u4e00\u4e2a\u5bf9\u8c61\u6765\u5b58\u50a8\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">    var t=function()\n    {\n      int a=1;\n      a=a+1;\n      alert(a);\n    } \n\n<\/pre>\n\n\n\n<p>\u5728java\u4e2d\uff0c\u76f4\u5230java8\u7684lambda\u7684\u7279\u6027\u95ee\u4e16\uff0c\u624d\u6709\u529e\u6cd5\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898<\/p>\n\n\n\n<p><strong>\u4ec0\u4e48\u662fLambda<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p>Lambda\u8868\u8fbe\u5f0f\u662fJDK 8\u5f00\u59cb\u540e\u7684\u4e00\u79cd\u65b0\u8bed\u6cd5\u5f62\u5f0f\u3002\u7b80\u5355\u6765\u8bf4\uff0c\u7f16\u7a0b\u4e2d\u63d0\u5230\u7684 lambda \u8868\u8fbe\u5f0f\uff0c\u901a\u5e38\u662f\u6307\u9700\u8981\u4e00\u4e2a\u51fd\u6570\uff0c\u4f46\u662f\u53c8\u4e0d\u60f3\u8d39\u795e\u53bb\u547d\u540d\u4e00\u4e2a\u51fd\u6570\u7684\u573a\u5408\u4e0b\u4f7f\u7528\uff0c\u4e5f\u5c31\u662f\u6307\u533f\u540d\u51fd\u6570\u3002<\/p>\n\n\n\n<p>\u53ef\u4ee5\u8bf4 lambda\u7684\u8868\u8fbe\u5f0f\u5176\u5b9e\u662f\u63a5\u53e3\u7684\u5b9e\u73b0\u7684\u201c\u53e6\u4e00\u79cd\u65b9\u5f0f\u201d\u3002\u8fd9\u79cd\u65b9\u5f0f\u66f4\u52a0\u7b80\u6d01\uff0c\u66f4\u5bb9\u6613\u9605\u8bfb\u3002\u9664\u4e86\u4ee3\u7801\u5c42\u9762\u7684\u7b80\u6d01\u5916\uff0c\u5728\u7f16\u8bd1\u7684\u7ed3\u679c\u65f6\u5019lambda\u4e5f\u4e0d\u4f1a\u4ea7\u751f\u4e00\u4e2a\u591a\u4f59\u7684\u533f\u540d\u7c7b\u3002<\/p>\n\n\n\n<p>\u4e00\u822c\u6211\u4eec\u4f7f\u7528\u53d8\u91cf\u6765\u8fdb\u884c\u8d4b\u503c\u64cd\u4f5c\uff1a<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2022\/07\/\u56fe\u7247-252-1024x248.png\" alt=\"\" class=\"wp-image-6677\" width=\"611\" height=\"148\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2022\/07\/\u56fe\u7247-252-1024x248.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2022\/07\/\u56fe\u7247-252-300x73.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2022\/07\/\u56fe\u7247-252-768x186.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2022\/07\/\u56fe\u7247-252-1536x373.png 1536w, https:\/\/92it.top\/wp-content\/uploads\/2022\/07\/\u56fe\u7247-252-830x201.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2022\/07\/\u56fe\u7247-252-230x56.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2022\/07\/\u56fe\u7247-252-350x85.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2022\/07\/\u56fe\u7247-252-480x116.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2022\/07\/\u56fe\u7247-252.png 1632w\" sizes=\"(max-width: 611px) 100vw, 611px\" \/><\/figure><\/div>\n\n\n\n<p>\u4f46\u662f\u5728 Java8 \u4e4b\u524d\u662f\u6ca1\u6709\u63d0\u4f9b\u5c06\u4e00\u4e2a\u65b9\u6cd5\u8d4b\u503c\u7ed9\u4e00\u4e2a\u53d8\u91cf\u7684\u64cd\u4f5c\uff1a<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2022\/07\/\u56fe\u7247-253-1024x282.png\" alt=\"\" class=\"wp-image-6678\" width=\"615\" height=\"169\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2022\/07\/\u56fe\u7247-253-1024x282.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2022\/07\/\u56fe\u7247-253-300x83.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2022\/07\/\u56fe\u7247-253-768x211.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2022\/07\/\u56fe\u7247-253-1536x422.png 1536w, https:\/\/92it.top\/wp-content\/uploads\/2022\/07\/\u56fe\u7247-253-830x228.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2022\/07\/\u56fe\u7247-253-230x63.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2022\/07\/\u56fe\u7247-253-350x96.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2022\/07\/\u56fe\u7247-253-480x132.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2022\/07\/\u56fe\u7247-253.png 1636w\" sizes=\"(max-width: 615px) 100vw, 615px\" \/><\/figure><\/div>\n\n\n\n<p>\u5728 JavaScript \u4e2d\u6709 \u95ed\u5305\u7684\u6982\u5ff5\uff0c\u6240\u4ee5 Java\u4e0d\u7518\u843d\u540e\uff0c\u4e5f\u53bb\u5b66\u4e60\u4e86\u4eba\u5bb6\uff0c\u641e\u51fa\u4e86\u533f\u540d\u51fd\u6570\u7684\u6982\u5ff5\u3002<\/p>\n\n\n\n<p>\u5728Java 8\u91cc\u9762\uff0c\u6240\u6709\u7684Lambda\u7684\u7c7b\u578b\u90fd\u662f\u4e00\u4e2a\u63a5\u53e3\uff0c\u800cLambda\u8868\u8fbe\u5f0f\u672c\u8eab\uff0c\u4e5f\u5c31\u662f\u201d\u90a3\u6bb5\u4ee3\u7801\u201c\uff0c\u9700\u8981\u662f\u8fd9\u4e2a\u63a5\u53e3\u7684\u5b9e\u73b0\u3002\u8fd9\u662f\u6211\u8ba4\u4e3a\u7406\u89e3Lambda\u7684\u4e00\u4e2a\u5173\u952e\u6240\u5728\uff0c\u7b80\u800c\u8a00\u4e4b\u5c31\u662f\uff0cLambda\u8868\u8fbe\u5f0f\u672c\u8eab\u5c31\u662f\u4e00\u4e2a\u63a5\u53e3\u7684\u5b9e\u73b0\u3002<\/p>\n\n\n\n<p>\u57fa\u672c\u8bed\u6cd5\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">    (parameters) -> { expression or statements }\n<\/pre>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">(\u533f\u540d\u5185\u90e8\u7c7b\u88ab\u91cd\u5199\u65b9\u6cd5\u7684\u5f62\u53c2\u5217\u8868) -> {\n\t\u91cd\u5199\u65b9\u6cd5\n}<\/pre>\n\n\n\n<p>\u793a\u4f8b\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\/\/ \u65e0\u53c2\u6570, \u8fd4\u56de1+2\u7684\u7ed3\u679c\n() -> 1+2;\n \n\/\/ \u63a5\u6536\u4e00\u4e2a\u53c2\u6570(\u6570\u5b57\u7c7b\u578b),\u8fd4\u56de\u51762\u500d\u7684\u503c\nx -> 2 * x;\n \n\/\/ \u63a5\u65362\u4e2a\u53c2\u6570(\u6570\u5b57),\u8fd4\u56de\u8868\u8fbe\u5f0f\u8fd0\u7b97\u7684\u7ed3\u679c\n(x, y) -> x + y;\n \n\/\/ \u591a\u4e2a\u8bed\u53e5\u8981\u7528\u5927\u62ec\u53f7\u5305\u88f9, \u5e76\u4e14\u8fd4\u56de\u503c\u8981\u7528return\u6307\u660e\n(x, y) -> {\n    int result = x + y;\n    System.out.print(result);\n    return result;\n};<\/pre>\n\n\n\n<p>Lambda\u8868\u8fbe\u5f0f\u6709\u5982\u4e0b\u7ea6\u5b9a\uff1a<\/p>\n\n\n\n<ul><li>\u4e00\u4e2a Lambda \u8868\u8fbe\u5f0f\u53ef\u4ee5\u6709\u96f6\u4e2a\u6216\u591a\u4e2a\u53c2\u6570\uff1b <\/li><li>\u53c2\u6570\u7684\u7c7b\u578b\u65e2\u53ef\u4ee5\u660e\u786e\u58f0\u660e\uff0c\u4e5f\u53ef\u4ee5\u6839\u636e\u4e0a\u4e0b\u6587\u6765\u63a8\u65ad\u3002\u4f8b\u5982\uff1a(int a)\u4e0e(a)\u6548\u679c\u76f8\u540c\uff1b <\/li><li>\u6240\u6709\u53c2\u6570\u9700\u5305\u542b\u5728\u5706\u62ec\u53f7\u5185\uff0c\u53c2\u6570\u4e4b\u95f4\u7528\u9017\u53f7\u76f8\u9694\u3002\u4f8b\u5982\uff1a(a, b) \u6216 (int a, int b) \u6216 (String a, int b, float c)\uff1b<\/li><li> \u7a7a\u5706\u62ec\u53f7\u4ee3\u8868\u53c2\u6570\u96c6\u4e3a\u7a7a\u3002\u4f8b\u5982\uff1a() -&gt; 42\uff1b <\/li><li>\u5f53\u53ea\u6709\u4e00\u4e2a\u53c2\u6570\uff0c\u4e14\u5176\u7c7b\u578b\u53ef\u63a8\u5bfc\u65f6\uff0c\u5706\u62ec\u53f7\uff08\uff09\u53ef\u7701\u7565\u3002\u4f8b\u5982\uff1aa -&gt; return a*a\uff1b<\/li><li> Lambda \u8868\u8fbe\u5f0f\u7684\u4e3b\u4f53\u53ef\u5305\u542b\u96f6\u6761\u6216\u591a\u6761\u8bed\u53e5\uff1b <\/li><li>\u5982\u679c Lambda \u8868\u8fbe\u5f0f\u7684\u4e3b\u4f53\u53ea\u6709\u4e00\u6761\u8bed\u53e5\uff0c\u82b1\u62ec\u53f7{}\u53ef\u7701\u7565\u3002\u533f\u540d\u51fd\u6570\u7684\u8fd4\u56de\u7c7b\u578b\u4e0e\u8be5\u4e3b\u4f53\u8868\u8fbe\u5f0f\u4e00\u81f4\uff1b <\/li><li>\u5982\u679c Lambda \u8868\u8fbe\u5f0f\u7684\u4e3b\u4f53\u5305\u542b\u4e00\u6761\u4ee5\u4e0a\u8bed\u53e5\uff0c\u5219\u8868\u8fbe\u5f0f\u5fc5\u987b\u5305\u542b\u5728\u82b1\u62ec\u53f7{}\u4e2d\uff08\u5f62\u6210\u4ee3\u7801\u5757\uff09\u3002\u533f\u540d\u51fd\u6570\u7684\u8fd4\u56de\u7c7b\u578b\u4e0e\u4ee3\u7801\u5757\u7684\u8fd4\u56de\u7c7b\u578b\u4e00\u81f4\uff0c\u82e5\u6ca1\u6709\u8fd4\u56de\u5219\u4e3a\u7a7a\u3002<\/li><\/ul>\n\n\n\n<p>@FunctionalInterface \u662f Java 8 \u65b0\u52a0\u5165\u7684\u4e00\u79cd\u63a5\u53e3\uff0c\u7528\u4e8e\u6307\u660e\u8be5\u63a5\u53e3\u7c7b\u578b\u58f0\u660e\u662f\u6839\u636e Java \u8bed\u8a00\u89c4\u8303\u5b9a\u4e49\u7684\u51fd\u6570\u5f0f\u63a5\u53e3\u3002Java 8 \u8fd8\u58f0\u660e\u4e86\u4e00\u4e9b Lambda \u8868\u8fbe\u5f0f\u53ef\u4ee5\u4f7f\u7528\u7684\u51fd\u6570\u5f0f\u63a5\u53e3\uff0c\u5f53\u4f60\u6ce8\u91ca\u7684\u63a5\u53e3\u4e0d\u662f\u6709\u6548\u7684\u51fd\u6570\u5f0f\u63a5\u53e3\u65f6\uff0c\u53ef\u4ee5\u4f7f\u7528 @FunctionalInterface \u89e3\u51b3\u7f16\u8bd1\u5c42\u9762\u7684\u9519\u8bef\u3002<\/p>\n\n\n\n<p>\u4ec0\u4e48\u662f\u51fd\u6570\u5f0f\u63a5\u53e3\uff1f<\/p>\n\n\n\n<ul><li>\u9996\u5148\u5fc5\u987b\u662f\u63a5\u53e3\u3001\u5176\u6b21\u63a5\u53e3\u4e2d\u6709\u4e14\u4ec5\u6709\u4e00\u4e2a\u62bd\u8c61\u65b9\u6cd5\u7684\u5f62\u5f0f<\/li><li>\u901a\u5e38\u4f1a\u5728\u63a5\u53e3\u4e0a\u52a0\u4e0a\u4e00\u4e2a@FunctionalInterface\u6ce8\u89e3\uff0c\u6807\u8bb0\u8be5\u63a5\u53e3\u5fc5\u987b\u662f\u6ee1\u8db3\u51fd\u6570\u5f0f\u63a5\u53e3<\/li><\/ul>\n\n\n\n<p>\u6839\u636e\u5b9a\u4e49\uff0c\u51fd\u6570\u5f0f\u63a5\u53e3\u53ea\u80fd\u6709\u4e00\u4e2a\u62bd\u8c61\u65b9\u6cd5\uff0c\u5982\u679c\u4f60\u5c1d\u8bd5\u6dfb\u52a0\u7b2c\u4e8c\u4e2a\u62bd\u8c61\u65b9\u6cd5\uff0c\u5c06\u629b\u51fa\u7f16\u8bd1\u65f6\u9519\u8bef\u3002\u4f8b\u5982\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">@FunctionalInterface\npublic interface DoSomethingInterface {\n \n  void doSomeThing();\n \n  void doSomeThing1();\n \n}<\/pre>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2022\/07\/\u56fe\u7247-254-1024x220.png\" alt=\"\" class=\"wp-image-6679\" width=\"606\" height=\"130\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2022\/07\/\u56fe\u7247-254-1024x220.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2022\/07\/\u56fe\u7247-254-300x65.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2022\/07\/\u56fe\u7247-254-768x165.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2022\/07\/\u56fe\u7247-254-1536x330.png 1536w, https:\/\/92it.top\/wp-content\/uploads\/2022\/07\/\u56fe\u7247-254-830x179.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2022\/07\/\u56fe\u7247-254-230x49.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2022\/07\/\u56fe\u7247-254-350x75.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2022\/07\/\u56fe\u7247-254-480x103.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2022\/07\/\u56fe\u7247-254.png 1618w\" sizes=\"(max-width: 606px) 100vw, 606px\" \/><\/figure><\/div>\n\n\n\n<p>\u4e3e\u4e00\u4e2a\u7b80\u5355\u4f7f\u7528\u7684\u4f8b\u5b50,\u9996\u5148\u5b9a\u4e49\u4e00\u4e2a\u63a5\u53e3\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">@FunctionalInterface\npublic interface DoSomethingInterface&lt;T> {\n \n  String doSomeThing(T t);\n \n}<\/pre>\n\n\n\n<p>\u8fd9\u4e2a\u63a5\u53e3\u91cc\u9762\u53ea\u80fd\u6709\u4e00\u4e2a\u51fd\u6570\uff0c\u63a5\u53e3\u91cc\u662f\u8fd4\u56de\u503c\u4e3aString\u7c7b\u578b\u7684\u65b9\u6cd5\uff0c\u90a3\u4e48\u4e0b\u9762\u4f7f\u7528\u5b83\u7684\u65f6\u5019\u5c31\u9700\u8981\u6709\u8fd4\u56de\u503c\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">class MainTest{\n \n   public static void main(String[] args) {\n \n     DoSomethingInterface&lt;String> t = str -> {\n       return str;\n     };\n     String print = t.doSomeThing(\"print\");\n     System.out.println(print);\n \n   }\n}<\/pre>\n\n\n\n<p>t\u5c31\u76f8\u5f53\u4e8e\u662f\u63a5\u53e3\u7684\u5177\u4f53\u5b9e\u73b0\uff0c\u90a3\u4e48\u4f7f\u7528 t.doSomeThing(&#8220;print&#8221;)\u5c31\u4f1a\u53bb\u8c03\u7528 t \u7684\u533f\u540d\u51fd\u6570\u6267\u884c\u3002\u4ece\u8fd9\u6bb5\u4ee3\u7801\u770b,\u5982\u679c\u6211\u4eec\u6709\u4e00\u4e2a\u62bd\u8c61\u7c7b\u7684\u5177\u4f53\u5b9e\u73b0\u903b\u8f91\u76f8\u5bf9\u7b80\u5355\u4e0d\u7528\u5927\u6bb5\u4ee3\u7801\u7684\u65f6\u5019\uff0c\u53ef\u4ee5\u4f7f\u7528 Lambda \u8868\u8fbe\u5f0f\u53bb\u5b9e\u73b0\u5177\u4f53\u7684\u903b\u8f91\uff0c\u8fd9\u6837\u5c31\u4e0d\u7528new \u591a\u4e2a\u7c7b\u3002<\/p>\n\n\n\n<p><strong>Java 8 \u5185\u7f6e4\u5927\u6838\u5fc3\u51fd\u6570\u5f0f\u63a5\u53e3<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p>\u5927\u5bb6\u65e5\u5e38\u4f7f\u7528\u7684List\uff0cMap\uff0c\u80af\u5b9a\u5927\u91cf\u4f7f\u7528\u4e86Stream\u6d41\u5f0f\u5904\u7406\uff0c\u5728\u6d41\u5f0f\u5904\u7406\u4e2d\u5927\u91cf\u4f7f\u7528\u4e86Lambda\uff0c\u6bd4\u5982List\u7684foreach\u65b9\u6cd5\u5c31\u4f7f\u7528\u4e86Lambda\u8868\u8fbe\u5f0f\u3002Java8\u4e2d\u62bd\u8c61\u51fa\u67654\u7c7b\u57fa\u672c\u7684\u51fd\u6570\u5f0f\u63a5\u53e3\uff0c\u65e5\u5e38\u5f00\u53d1\u4e2d\u6211\u4eec\u5176\u5b9e\u4e5f\u662f\u53ef\u4ee5\u4f7f\u7528\u7684\u3002<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2022\/07\/\u56fe\u7247-256-1024x266.png\" alt=\"\" class=\"wp-image-6684\" width=\"563\" height=\"146\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2022\/07\/\u56fe\u7247-256-1024x266.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2022\/07\/\u56fe\u7247-256-300x78.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2022\/07\/\u56fe\u7247-256-768x200.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2022\/07\/\u56fe\u7247-256-1536x400.png 1536w, https:\/\/92it.top\/wp-content\/uploads\/2022\/07\/\u56fe\u7247-256-830x216.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2022\/07\/\u56fe\u7247-256-230x60.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2022\/07\/\u56fe\u7247-256-350x91.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2022\/07\/\u56fe\u7247-256-480x125.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2022\/07\/\u56fe\u7247-256.png 1668w\" sizes=\"(max-width: 563px) 100vw, 563px\" \/><\/figure><\/div>\n\n\n\n<p>\u4ee5\u4e0a4\u79cd\u7c7b\u578b\u662fJava\u9ed8\u8ba4\u63d0\u4f9b\u7684Lambda\u7c7b\uff0c\u5f00\u7bb1\u5373\u7528\u3002<\/p>\n\n\n\n<p>Consumer\u4f7f\u7528\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">public void test(){\n save(user, t->{ saveUser(t); });\n}\n \npublic void save(User user, Consumer&lt;User> consumer){\n consumer.accept(user);\n}<\/pre>\n\n\n\n<p>Supplier\u4f7f\u7528\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">public void test(){\n \n Config config = getConfig(t -> {\n  return getAllConfig(t);\n });\n \n}\n \npublic Config getConfig(Supplier&lt;Config> supplier) {\n return supplier.get();\n}<\/pre>\n\n\n\n<p>Function\u4f7f\u7528\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">public void test(){\n User user = getUser(t -> { return getUserByName(t); });\n}\n \npublic User getUser(Function&lt;String, User> function) {\n return function.apply(t);\n}<\/pre>\n\n\n\n<p>Predicate\u4f7f\u7528\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">public void test(){\n boolean b = checkStatus(user, t -> {\n  return checkUserExist(t);\n });\n \n}\n \npublic boolean checkStatus(User user, Predicate&lt;User> predicate) {\n return predicate.test(user);\n}<\/pre>\n\n\n\n<p><strong>\u5982\u4f55\u4f7f\u7528Lambda\uff1f<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p>\u6211\u4eec\u5c06\u6839\u636e\u4e0b\u9762\u4e09\u4e2a\u95ee\u9898\u6765\u5e2e\u52a9\u5927\u5bb6\u7406\u89e3\u548c\u4f7f\u7528Lambda<\/p>\n\n\n\n<p>\u80cc\u666f\uff1a\u6211\u4eec\u81ea\u5b9a\u4e49\u4e86\u4e00\u4e2aman\u7684\u7c7b\uff0c\u521b\u5efa\u4e86\u4e00\u4e2aman\u7684List\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">class man {\n    public int age;\n    public char sex;\n    public double socre;\n\n    public man(int age, char sex, double score) {\n        this.age = age;\n        this.sex = sex;\n        this.score = score;\n    }\n}\n<\/pre>\n\n\n\n<p><strong>\u95ee\u9898\u4e00\uff1a\u73b0\u9700\u8981\u5bf9\u8fd9\u4e2alist\u6839\u636e\u4eba\u7684\u5e74\u9f84\u8fdb\u884c\u6392\u5e8f<\/strong><\/p>\n\n\n\n<p>\u8981\u5b9e\u73b0\u6392\u5e8f\u7684\u529f\u80fd\uff0c\u53ef\u4ee5\u76f4\u63a5\u8c03\u7528List\u5bf9\u8c61\u81ea\u5e26\u7684sort\u65b9\u6cd5\u5b8c\u6210\uff0c\u4f46\u662f\u9700\u8981man\u5148\u5b9e\u73b0Comparator\u7684\u63a5\u53e3\u5e76\u91cd\u5199compare\u65b9\u6cd5\uff0c\u7f16\u8bd1\u5668\u624d\u80fd\u6bd4\u8f83\u4e24\u4e2a\u4e0d\u540cman\u7684\u5927\u5c0f\u3002\u4f46\u662f\u8981\u66f4\u6539\u539f\u59cb\u7c7b\u7684\u4ee3\u7801\uff0c\u4f1a\u6bd4\u8f83\u9ebb\u70e6\uff0c\u5982\u679c\u4ee5\u540e\u8981\u5bf9\u4eba\u7684\u5206\u6570\u8fdb\u884c\u6392\u5e8f\uff0c\u90a3\u5c31\u53c8\u8981\u66f4\u6539\u7684\u7c7b\u7684\u6e90\u7801\uff0c\u8fd9\u6837\u64cd\u4f5c\u5f88\u4e0d\u65b9\u4fbf\u3002<br><code>sort(Comparator&lt;? super E&gt; c)<\/code>&nbsp;\u65b9\u6cd5\u53ef\u4ee5\u76f4\u63a5\u4f20\u5165\u4e00\u4e2aComparator\u5bf9\u8c61\uff0c\u6211\u4eec\u53ef\u4ee5\u76f4\u63a5\u6539\u5199compare\u65b9\u6cd5\u5c31\u53ef\u4ee5\u5b9e\u73b0\u6bd4\u8f83\u3002<\/p>\n\n\n\n<p>\u7b2c\u4e00\u79cd\u5199\u6cd5\uff1a\u5e38\u89c4<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">public class lambdaTry {\n    public static void main(String[] args) {\n        List&lt;man> humans = new ArrayList&lt;>();\n        humans.add(new man(19, 'g', 98.0));\n        humans.add(new man(18, 'b', 95.0));\n        humans.add(new man(20, 'b', 96.0));\n        humans.add(new man(17, 'g', 97.0));\n\n        humans.sort(new Comparator&lt;man>() {\n            @Override\n            public int compare(man o1, man o2) {\n                return o1.age - o2.age;\n            }\n        });\n    }\n}\n<\/pre>\n\n\n\n<p>\u7b2c\u4e8c\u79cd\u5199\u6cd5\uff1aLambda<\/p>\n\n\n\n<p>\u6211\u4eec\u77e5\u9053Lambda\u662f\u7528\u6765\u7b80\u5316\u51fd\u6570\u5f0f\u63a5\u53e3\u7684\u533f\u540d\u5185\u90e8\u7c7b\uff0c\u4e14Comparator\u6ee1\u8db3\u51fd\u6570\u5f0f\u63a5\u53e3\u7684\u4e24\u4e2a\u6761\u4ef6\uff1a<\/p>\n\n\n\n<ul><li>\u9996\u5148\u5fc5\u987b\u662f\u63a5\u53e3\u3001\u5176\u6b21\u63a5\u53e3\u4e2d\u6709\u4e14\u4ec5\u6709\u4e00\u4e2a\u62bd\u8c61\u65b9\u6cd5\u7684\u5f62\u5f0f<\/li><li>@FunctionalInterface\u6ce8\u89e3<\/li><\/ul>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">@FunctionalInterface\npublic interface Comparator&lt;T> {\n\tint compare(T o1, T o2);\n    ...\n}<\/pre>\n\n\n\n<p>\u56e0\u6b64\u6211\u4eec\u53ef\u4ee5\u5bf9\u4e0a\u8ff0\u7684\u6e90\u7801\u8fdb\u884c\u6539\u5199\u6210Lambda\u683c\u5f0f<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">public class lambdaTry {\n    public static void main(String[] args) {\n        List&lt;man> humans = new ArrayList&lt;>();\n        humans.add(new man(19, 'g', 98.0));\n        humans.add(new man(18, 'b', 95.0));\n        humans.add(new man(20, 'b', 96.0));\n        humans.add(new man(17, 'g', 97.0));\n\n        humans.sort((man o1, man o2) -> {\n                return o1.age - o2.age;\n        });\n    }\n}\n<\/pre>\n\n\n\n<p>\u6539\u5199\u8fc7\u540e\u4ee3\u7801\u7b80\u6d01\u4e86\u5f88\u591a\u3002\u4f46\u662f\u8fd8\u53ef\u4ee5\u7ee7\u7eed\u7b80\u5199\u3002<\/p>\n\n\n\n<p>Lambda\u8868\u8fbe\u5f0f\u7684\u7701\u7565\u5199\u6cd5<\/p>\n\n\n\n<ul><li>\u53c2\u6570\u7c7b\u578b\u53ef\u4ee5\u4e0d\u5199<\/li><li>\u5982\u679c\u53ea\u6709\u4e00\u4e2a\u53c2\u6570\uff0c\u53c2\u6570\u7c7b\u578b\u53ef\u4ee5\u7701\u7565\uff0c\u540c\u65f6()\u4e5f\u53ef\u4ee5\u7701\u7565<\/li><li>\u5982\u679cLambda\u8868\u8fbe\u5f0f\u7684\u65b9\u6cd5\u5757\u4e2d\u4ee3\u7801\u53ea\u6709\u4e00\u884c\uff0c\u53ef\u4ee5\u7701\u7565\u5927\u62ec\u53f7\uff0c\u540c\u65f6\u7701\u7565\u5206\u53f7\u3002<\/li><li>\u5728\u6761\u4ef6\u4e09\u7684\u57fa\u7840\u4e0a\uff0c\u5982\u679c\u8fd9\u884c\u4ee3\u7801\u662freturn\u8bed\u53e5\uff0c\u5fc5\u987b\u7701\u7565return\u3002<\/li><\/ul>\n\n\n\n<p>\u7b2c\u4e09\u79cd\u5199\u6cd5\uff1aLambda\u7b80\u5199<\/p>\n\n\n\n<p>\u53ef\u4ee5\u770b\u5230\uff0c\u6b64\u8868\u8fbe\u5f0f\u6ee1\u8db3\u7701\u7565\u5199\u6cd5\u7684\u6761\u4ef6\uff0c\u53ef\u4ee5\u7ee7\u7eed\u7b80\u5199\u6210\u5982\u4e0b\u683c\u5f0f\u3002\u53ea\u9700\u8981\u4e00\u884c\u8bed\u53e5\u5c31\u80fd\u5b8c\u6210<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">public class lambdaTry {\n    public static void main(String[] args) {\n        List&lt;man> humans = new ArrayList&lt;>();\n        humans.add(new man(19, 'g', 98.0));\n        humans.add(new man(18, 'b', 95.0));\n        humans.add(new man(20, 'b', 96.0));\n        humans.add(new man(17, 'g', 97.0));\n\n        humans.sort((o1, o2) -> o1.age - o2.age);\n    }\n}\n<\/pre>\n\n\n\n<p><strong>\u95ee\u9898\u4e8c\uff1a\u5c06List\u8f6c\u6362\u4e3a\u6570\u7ec4<\/strong><\/p>\n\n\n\n<p>\u6211\u4eec\u77e5\u9053List\u63a5\u53e3\u6709\u4e00\u4e2a\u65b9\u6cd5toArray\u65b9\u6cd5\u53ef\u4ee5\u5b9e\u73b0\u5c06\u5176\u8f6c\u6362\u4e3a\u6570\u7ec4\u3002<\/p>\n\n\n\n<p>JDK11\u4e4b\u540e\uff0c\u63d0\u4f9b\u4e86\u8fd9\u6837\u7684\u4e00\u4e2a\u65b9\u6cd5\uff0c\u63d0\u4f9b\u4e86\u4e00\u4e2a\u51fd\u6570\u5f0f\u63a5\u53e3\u6765\u8ba9\u6211\u4eec\u8f6c\u6362<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">default &lt;T> T[] toArray(IntFunction&lt;T[]> generator) {\n    return toArray(generator.apply(0));\n}<\/pre>\n\n\n\n<p>IntFunction\u51fd\u6570\u5f0f\u63a5\u53e3\u662f\u4eceJDK8\u4e4b\u540e\u5b9e\u73b0\u7684\uff0c\u5185\u90e8\u53ea\u6709\u4e00\u4e2aapply\u62bd\u8c61\u65b9\u6cd5\uff0c\u662f\u4e00\u4e2a\u6807\u51c6\u7684\u51fd\u6570\u5f0f\u63a5\u53e3<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">@FunctionalInterface\npublic interface IntFunction&lt;R> {\n    R apply(int value);\n}<\/pre>\n\n\n\n<p>\u6211\u4eec\u53ef\u4ee5\u76f4\u63a5\u7528lambda\uff0c\u5b8c\u6210\u6570\u7ec4\u7684\u8f6c\u6362<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">public class lambdaTry {\n    public static void main(String[] args) {\n        List&lt;man> humans = new ArrayList&lt;>();\n        humans.add(new man(19, 'g', 98.0));\n        humans.add(new man(18, 'b', 95.0));\n        humans.add(new man(20, 'b', 96.0));\n        humans.add(new man(17, 'g', 97.0));\n\n        \/\/ \u539f\u672c\u5199\u6cd5\n        \/\/ man[] mans = humans.toArray(new IntFunction&lt;man[]>() {\n        \/\/     @Override\n        \/\/     public man[] apply(int value) {\n        \/\/         return new man[value];\n        \/\/     }\n        \/\/ });\n\n        \/\/ lambda\u5199\u6cd5\n        man[] mans = humans.toArray(value -> new man[value]);\n        \n        \/\/ \u5b9e\u9645\u4e0a\u7528\u4e0d\u4e0a\u8fd9\u6837\u7684\u5199\u6cd5\uff0c\u53ea\u662f\u4e3a\u4e86\u4e3e\u4f8b\u8bf4\u660e\n        \/\/ man[] mans = humans.toArray(new man[0]);\n        \/\/ man[] mans = humans.toArray(man[]::new);\n        \/\/ \u4e0a\u9762\u4e24\u79cd\u5199\u6cd5\u90fd\u53ef\u4ee5\uff0c\u4f20\u503c\u8fdb\u53bb\u7684size\u4e3a0\u4e0d\u5f71\u54cd\u5b9e\u9645\u7684\u8f6c\u6362\uff0c\u5177\u4f53\u53ef\u4ee5\u770bArrayList\u7684toArray\u91cd\u5199\u65b9\u6cd5\n        \n    }\n}\n<\/pre>\n\n\n\n<p><strong>\u95ee\u9898\u4e09\uff1a\u8f93\u51fa\u5e74\u9f84\u5927\u4e8e18\u7684\u7537\u540c\u5b66\u7684\u6210\u7ee9<\/strong><\/p>\n\n\n\n<p>\u53ef\u4ee5\u7528forEach\u65b9\u6cd5\u5feb\u6377\u5b9e\u73b0\uff0cforEach\u65b9\u6cd5\u6765\u81ea\u4e8eIterable\u63a5\u53e3<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">default void forEach(Consumer&lt;? super T> action) {\n    Objects.requireNonNull(action);\n    for (T t : this) {\n        action.accept(t);\n    }\n}<\/pre>\n\n\n\n<p>\u518d\u770bConsumer\u63a5\u53e3\uff0c\u4e5f\u662f\u4e00\u4e2a\u51fd\u6570\u5f0f\u63a5\u53e3<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">@FunctionalInterface\npublic interface Consumer&lt;T> {\n    void accept(T t);\n    ...\n}<\/pre>\n\n\n\n<p>\u5177\u4f53\u5b9e\u73b0<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">public class lambdaTry {\n    public static void main(String[] args) {\n        List&lt;man> humans = new ArrayList&lt;>();\n        humans.add(new man(19, 'g', 98.0));\n        humans.add(new man(18, 'b', 95.0));\n        humans.add(new man(20, 'b', 96.0));\n        humans.add(new man(17, 'g', 97.0));\n\n        \/\/ humans.forEach(new Consumer&lt;>() {\n        \/\/     @Override\n        \/\/     public void accept(man man) {\n        \/\/         if (man.age >= 18 &amp;&amp; man.sex == 'g') {\n        \/\/             System.out.println(man.score);\n        \/\/         }\n        \/\/     }\n        \/\/ });\n\n        humans.forEach(man -> {\n            if (man.age >= 18 &amp;&amp; man.sex == 'g') {\n                System.out.println(man.score);\n            }\n        });\n    }\n}\n<\/pre>\n\n\n\n<p>\u6709\u65f6Lambda\u8fd8\u53ef\u4ee5\u7ee7\u7eed\u7b80\u5199\u6210\u65b9\u6cd5\u5f15\u7528\uff08method reference\uff09<\/p>\n\n\n\n<p><strong>\u65b9\u6cd5\u5f15\u7528<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p>\u65b9\u6cd5\u5f15\u7528\u901a\u8fc7\u65b9\u6cd5\u7684\u540d\u5b57\u6765\u6307\u5411\u4e00\u4e2a\u65b9\u6cd5\u3002<\/p>\n\n\n\n<p>\u65b9\u6cd5\u5f15\u7528\u53ef\u4ee5\u4f7f\u8bed\u8a00\u7684\u6784\u9020\u66f4\u7d27\u51d1\u7b80\u6d01\uff0c\u51cf\u5c11\u5197\u4f59\u4ee3\u7801\u3002<\/p>\n\n\n\n<p>\u65b9\u6cd5\u5f15\u7528\u4f7f\u7528\u4e00\u5bf9\u5192\u53f7&nbsp;<strong>::<\/strong><\/p>\n\n\n\n<p>\u4e3b\u8981\u5206\u4e3a\u56db\u79cd\uff1a<\/p>\n\n\n\n<ul><li>\u6784\u9020\u5668\u5f15\u7528 Class::newman[] <\/li><\/ul>\n\n\n\n<ul><li>\u9759\u6001\u65b9\u6cd5\u5f15\u7528 Class::static_method<\/li><\/ul>\n\n\n\n<ul><li>\u7279\u5b9a\u7c7b\u7684\u4efb\u610f\u5bf9\u8c61\u7684\u65b9\u6cd5\u5f15\u7528 Class::method<\/li><\/ul>\n\n\n\n<ul><li>\u7279\u5b9a\u5bf9\u8c61\u7684\u65b9\u6cd5\u5f15\u7528 instance::method<\/li><\/ul>\n\n\n\n<p>\u4ee5\u4e0a\u5173\u4e8eLambda\u5c31\u4ecb\u7ecd\u5230\u8fd9\u91cc\uff0c\u5927\u5bb6\u5e94\u8be5\u660e\u767d\u4e86\u5b83\u662f\u5e72\u5565\u7684\u4e86\u5427\u3002\u95ed\u5305\u662f\u4e0d\u662f\u4e5f\u6ca1\u6709\u8fd9\u4e48\u96be\u61c2\u5462\uff01\u8054\u60f3\u5230List\u7684foreach\u4f7f\u7528\uff0c\u5927\u5bb6\u6709\u6ca1\u6709\u51b2\u52a8\u60f3\u81ea\u5df1\u5b9e\u73b0\u4e00\u4e2aLambda\u5728\u65e5\u5e38\u5f00\u53d1\u4e2d\u70ab\u4e00\u628a\uff08\u5982\u679c\u522b\u4eba\u770b\u4e0d\u61c2\uff0c\u4f1a\u6253\u4f60\u7684\uff09\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Java \u76ee\u524d\u5df2\u7ecf\u51fa\u523013\u7684\u7248\u672c\uff0c\u4f46\u662f\u56fd\u5185\u5927\u90e8\u5206\u516c\u53f8\u5e94\u8be5\u90fd\u505c\u7559\u5728 Java 8 \u7684\u7248\u672c\uff08\u4e0d\u6562\u627f\u62c5\u5347\u7ea7\u5e26\u6765\u7684\u98ce\u9669 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[26],"tags":[],"_links":{"self":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/6676"}],"collection":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=6676"}],"version-history":[{"count":6,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/6676\/revisions"}],"predecessor-version":[{"id":6719,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/6676\/revisions\/6719"}],"wp:attachment":[{"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6676"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=6676"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=6676"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}