{"id":38972,"date":"2024-11-26T10:30:08","date_gmt":"2024-11-26T02:30:08","guid":{"rendered":"https:\/\/fwq.ai\/blog\/38972\/"},"modified":"2024-11-26T10:30:08","modified_gmt":"2024-11-26T02:30:08","slug":"java%e6%80%8e%e4%b9%88%e5%a3%b0%e6%98%8e%e5%87%bd%e6%95%b0%e6%8c%87%e9%92%88%e6%95%b0%e7%bb%84%e9%95%bf%e5%ba%a6","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/38972\/","title":{"rendered":"java\u600e\u4e48\u58f0\u660e\u51fd\u6570\u6307\u9488\u6570\u7ec4\u957f\u5ea6"},"content":{"rendered":"<blockquote><p>\n  \u5728 java \u4e2d\uff0c\u51fd\u6570\u6307\u9488\u6570\u7ec4\u7684\u957f\u5ea6\u662f\u56fa\u5b9a\u7684\uff0c\u5e76\u4e14\u53ef\u4ee5\u901a\u8fc7\u5728\u521b\u5efa\u6570\u7ec4\u65f6\u6307\u5b9a\u957f\u5ea6\u6765\u786e\u5b9a\u3002\u8981\u58f0\u660e\u51fd\u6570\u6307\u9488\u6570\u7ec4\u7684\u957f\u5ea6\uff1a\u4f7f\u7528\u533f\u540d\u5185\u90e8\u7c7b\uff1afunctionpointer[] functionpointers = new functionpointer[length]\uff1b\u4f7f\u7528 lambda \u8868\u8fbe\u5f0f\uff1afunctionpointer[] functionpointers = new functionpointer[length]\uff1b\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202411\/15\/2024111520394937225.jpg\" class=\"aligncenter\" title=\"java\u600e\u4e48\u58f0\u660e\u51fd\u6570\u6307\u9488\u6570\u7ec4\u957f\u5ea6\u63d2\u56fe\" alt=\"java\u600e\u4e48\u58f0\u660e\u51fd\u6570\u6307\u9488\u6570\u7ec4\u957f\u5ea6\u63d2\u56fe\" \/><\/p>\n<p><strong>Java \u4e2d\u58f0\u660e\u51fd\u6570\u6307\u9488\u6570\u7ec4\u7684\u957f\u5ea6<\/strong><\/p>\n<p>Java \u8bed\u8a00\u4e2d\uff0c\u51fd\u6570\u6307\u9488\u5e76\u4e0d\u662f\u76f4\u63a5\u652f\u6301\u7684\u8bed\u6cd5\u7279\u6027\u3002\u4f46\u662f\uff0c\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528\u533f\u540d\u5185\u90e8\u7c7b\u6216 Lambda \u8868\u8fbe\u5f0f\u6765\u5b9e\u73b0\u7c7b\u4f3c\u4e8e\u51fd\u6570\u6307\u9488\u7684\u884c\u4e3a\uff0c\u800c\u6570\u7ec4\u5219\u53ef\u4ee5\u7528\u6765\u5b58\u50a8\u8fd9\u4e9b\u51fd\u6570\u6307\u9488\u3002<\/p>\n<p><strong>\u4f7f\u7528\u533f\u540d\u5185\u90e8\u7c7b\u58f0\u660e\u51fd\u6570\u6307\u9488\u6570\u7ec4\u7684\u957f\u5ea6\uff1a<\/strong><\/p>\n<pre>FunctionPointer[] functionPointers = new FunctionPointer[length];\n\nfor (int i = 0; i &lt; length; i++) {\n    functionPointers[i] = new FunctionPointer() {\n        @Override\n        public void execute() {\n            \/\/ \u51fd\u6570\u6307\u9488\u7684\u5b9e\u73b0\n        }\n    };\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u4f7f\u7528 Lambda \u8868\u8fbe\u5f0f\u58f0\u660e\u51fd\u6570\u6307\u9488\u6570\u7ec4\u7684\u957f\u5ea6\uff1a<\/strong><\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<pre>FunctionPointer[] functionPointers = new FunctionPointer[length];\n\nfor (int i = 0; i &lt; length; i++) {\n    functionPointers[i] = () -&gt; {\n        \/\/ \u51fd\u6570\u6307\u9488\u7684\u5b9e\u73b0\n    };\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5728 Java \u4e2d\uff0cFunctionPointer \u53ef\u4ee5\u5b9a\u4e49\u4e3a\u4e00\u4e2a\u51fd\u6570\u5f0f\u63a5\u53e3\uff0c\u5176\u4e2d\u5305\u542b\u4e00\u4e2a execute() \u65b9\u6cd5\uff0c\u8be5\u65b9\u6cd5\u7528\u4e8e\u6267\u884c\u51fd\u6570\u6307\u9488\u7684\u5b9e\u73b0\u3002<\/p>\n<p><strong>\u6ce8\u610f\u4e8b\u9879\uff1a<\/strong><\/p>\n<ul>\n<li>\u51fd\u6570\u6307\u9488\u6570\u7ec4\u7684\u957f\u5ea6\u662f\u56fa\u5b9a\u7684\uff0c\u5728\u521b\u5efa\u6570\u7ec4\u540e\u65e0\u6cd5\u66f4\u6539\u3002<\/li>\n<li>\u51fd\u6570\u6307\u9488\u6570\u7ec4\u4e2d\u7684\u6bcf\u4e2a\u5143\u7d20\u90fd\u6307\u5411\u4e00\u4e2a\u7279\u5b9a\u7684\u51fd\u6570\u6307\u9488\uff0c\u8be5\u51fd\u6570\u6307\u9488\u4e0d\u53ef\u66f4\u6539\u3002<\/li>\n<li>\u4f7f\u7528\u533f\u540d\u5185\u90e8\u7c7b\u548c Lambda \u8868\u8fbe\u5f0f\u5b9e\u73b0\u51fd\u6570\u6307\u9488\u65f6\uff0c\u9700\u8981\u786e\u4fdd\u51fd\u6570\u6307\u9488\u7684\u5b9e\u73b0\u4e0e\u51fd\u6570\u5f0f\u63a5\u53e3\u4e2d\u6307\u5b9a\u7684\u7b7e\u540d\u4e00\u81f4\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662fjava\u600e\u4e48\u58f0\u660e\u51fd\u6570\u6307\u9488\u6570\u7ec4\u957f\u5ea6\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728 java \u4e2d\uff0c\u51fd\u6570\u6307\u9488\u6570\u7ec4\u7684\u957f\u5ea6\u662f\u56fa\u5b9a\u7684\uff0c\u5e76\u4e14\u53ef\u4ee5\u901a\u8fc7\u5728\u521b\u5efa\u6570\u7ec4\u65f6\u6307\u5b9a\u957f\u5ea6\u6765\u786e\u5b9a\u3002\u8981\u58f0\u660e\u51fd\u6570\u6307\u9488\u6570\u7ec4\u7684\u957f\u5ea6\uff1a\u4f7f\u7528\u533f\u540d\u5185\u90e8\u7c7b\uff1afunctionpointer[] functionpointers = new functionpointer[length]\uff1b\u4f7f\u7528 lambda \u8868\u8fbe\u5f0f\uff1afunctionpointer[] functionpointers = new functionpointer[length]\uff1b Java \u4e2d\u58f0\u660e\u51fd\u6570\u6307\u9488\u6570\u7ec4\u7684\u957f\u5ea6 Java \u8bed\u8a00\u4e2d\uff0c\u51fd\u6570\u6307\u9488\u5e76\u4e0d\u662f\u76f4\u63a5\u652f\u6301\u7684\u8bed\u6cd5\u7279\u6027\u3002\u4f46\u662f\uff0c\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528\u533f\u540d\u5185\u90e8\u7c7b\u6216 Lambda \u8868\u8fbe\u5f0f\u6765\u5b9e\u73b0\u7c7b\u4f3c\u4e8e\u51fd\u6570\u6307\u9488\u7684\u884c\u4e3a\uff0c\u800c\u6570\u7ec4\u5219\u53ef\u4ee5\u7528\u6765\u5b58\u50a8\u8fd9\u4e9b\u51fd\u6570\u6307\u9488\u3002 \u4f7f\u7528\u533f\u540d\u5185\u90e8\u7c7b\u58f0\u660e\u51fd\u6570\u6307\u9488\u6570\u7ec4\u7684\u957f\u5ea6\uff1a FunctionPointer[] functionPointers = new FunctionPointer[length]; for (int i = 0; i &lt; length; i++) { functionPointers[i] = new FunctionPointer() { @Override public void execute() { \/\/ \u51fd\u6570\u6307\u9488\u7684\u5b9e\u73b0 } }; } \u767b\u5f55\u540e\u590d\u5236 \u4f7f\u7528 Lambda \u8868\u8fbe\u5f0f\u58f0\u660e\u51fd\u6570\u6307\u9488\u6570\u7ec4\u7684\u957f\u5ea6\uff1a \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-38972","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/38972","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=38972"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/38972\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=38972"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=38972"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=38972"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}