{"id":203029,"date":"2025-05-22T09:41:58","date_gmt":"2025-05-22T01:41:58","guid":{"rendered":"https:\/\/server.hk\/cnblog\/203029\/"},"modified":"2025-05-22T09:41:58","modified_gmt":"2025-05-22T01:41:58","slug":"%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8%e6%96%b9%e6%b3%95%e5%bc%95%e7%94%a8%e5%ae%9a%e4%b9%89-java-%e5%87%bd%e6%95%b0%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/203029\/","title":{"rendered":"\u5982\u4f55\u4f7f\u7528\u65b9\u6cd5\u5f15\u7528\u5b9a\u4e49 Java \u51fd\u6570\uff1f"},"content":{"rendered":"<p><b><\/b>     <\/p>\n<h1>\u5982\u4f55\u4f7f\u7528\u65b9\u6cd5\u5f15\u7528\u5b9a\u4e49 Java \u51fd\u6570\uff1f<\/h1>\n<p>\u4eca\u65e5\u4e0d\u80af\u57cb\u5934\uff0c\u660e\u65e5\u4f55\u4ee5\u62ac\u5934\uff01\u6bcf\u65e5\u4e00\u53e5\u52aa\u529b\u81ea\u5df1\u7684\u8bdd\u54c8\u54c8~\u54c8\u55bd\uff0c\u4eca\u5929\u6211\u5c06\u7ed9\u5927\u5bb6\u5e26\u6765\u4e00\u7bc7<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300a\u5982\u4f55\u4f7f\u7528\u65b9\u6cd5\u5f15\u7528\u5b9a\u4e49 Java \u51fd\u6570\uff1f\u300b<\/span>\uff0c\u4e3b\u8981\u5185\u5bb9\u662f\u8bb2\u89e3<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\u7b49\u7b49\uff0c\u611f\u5174\u8da3\u7684\u670b\u53cb\u53ef\u4ee5\u6536\u85cf\u6216\u8005\u6709\u66f4\u597d\u7684\u5efa\u8bae\u5728\u8bc4\u8bba\u63d0\u51fa\uff0c\u6211\u90fd\u4f1a\u8ba4\u771f\u770b\u7684\uff01\u5927\u5bb6\u4e00\u8d77\u8fdb\u6b65\uff0c\u4e00\u8d77\u5b66\u4e60\uff01<\/p>\n<p>\u65b9\u6cd5\u5f15\u7528\u662f\u4e00\u79cd\u8bed\u6cd5\uff0c\u5141\u8bb8\u6211\u4eec\u5c06\u73b0\u6709\u65b9\u6cd5\u4f5c\u4e3a\u53c2\u6570\u4f20\u9012\u7ed9\u5176\u4ed6\u65b9\u6cd5\u3002\u5b83\u6709\u4e24\u79cd\u8bed\u6cd5\uff1a\u5b9e\u4f8b\u65b9\u6cd5\u5f15\u7528\uff08\u7c7b\u540d::\u5b9e\u4f8b\u65b9\u6cd5\u540d\uff09\u548c\u9759\u6001\u65b9\u6cd5\u5f15\u7528\uff08\u7c7b\u540d::\u9759\u6001\u65b9\u6cd5\u540d\uff09\u3002\u4f7f\u7528\u65b9\u6cd5\u5f15\u7528\u53ef\u4ee5\u589e\u5f3a\u51fd\u6570\u5f0f\u7f16\u7a0b\uff0c\u6ce8\u518c\u4e8b\u4ef6\u5904\u7406\u7a0b\u5e8f\uff0c\u5e76\u63d0\u4f9b\u7b80\u6d01\u4e14\u9ad8\u6548\u7684 lambda \u8868\u8fbe\u5f0f\u66ff\u4ee3\u54c1\u3002\u5b83\u63d0\u4f9b\u4e86\u7b80\u6d01\u6027\u3001\u53ef\u8bfb\u6027\u548c\u6548\u7387\u7b49\u4f18\u70b9\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241027\/1730023721671e1129ba4ac.jpg\" class=\"aligncenter\"><\/p>\n<p><strong>\u5982\u4f55\u4f7f\u7528\u65b9\u6cd5\u5f15\u7528\u5b9a\u4e49 Java \u51fd\u6570<\/strong><\/p>\n<p>\u65b9\u6cd5\u5f15\u7528\u662f\u4e00\u79cd\u7b80\u6d01\u7684\u8bed\u6cd5\uff0c\u5b83\u5141\u8bb8\u6211\u4eec\u5c06\u73b0\u6709\u65b9\u6cd5\u4f5c\u4e3a\u53c2\u6570\u4f20\u9012\u7ed9\u5176\u4ed6\u65b9\u6cd5\u3002\u5b83\u5728 Java 8 \u4e2d\u5f15\u5165\uff0c\u63d0\u4f9b\u4e86\u66f4\u5f3a\u5927\u3001\u66f4\u5177\u53ef\u8bfb\u6027\u7684\u65b9\u5f0f\u6765\u5904\u7406\u51fd\u6570\u5f0f\u63a5\u53e3\u3002<\/p>\n<p><strong>\u8bed\u6cd5<\/strong><\/p>\n<p>\u65b9\u6cd5\u5f15\u7528\u6709\u4e24\u79cd\u57fa\u672c\u8bed\u6cd5\uff1a<\/p>\n<ul>\n<li><strong>\u5b9e\u4f8b\u65b9\u6cd5\u5f15\u7528\uff1a<\/strong><code>\u7c7b\u540d::\u5b9e\u4f8b\u65b9\u6cd5\u540d<\/code><\/li>\n<li><strong>\u9759\u6001\u65b9\u6cd5\u5f15\u7528\uff1a<\/strong><code>\u7c7b\u540d::\u9759\u6001\u65b9\u6cd5\u540d<\/code><\/li>\n<\/ul>\n<p><strong>\u793a\u4f8b<\/strong><\/p>\n<p><strong>\u5b9e\u4f8b\u65b9\u6cd5\u5f15\u7528\uff1a<\/strong><\/p>\n<pre>\/\/ \u521b\u5efa\u4e00\u4e2a List\uff0c\u5176\u4e2d\u5305\u542b\u5b57\u7b26\u4e32\nList&lt;String&gt; names = Arrays.asList(\"John\", \"Mary\", \"Bob\");\n\n\/\/ \u4f7f\u7528\u65b9\u6cd5\u5f15\u7528\u5bf9\u5217\u8868\u8fdb\u884c\u6392\u5e8f\nnames.sort(String::compareToIgnoreCase);\n\n\/\/ \u8f93\u51fa\u6392\u5e8f\u540e\u7684\u5217\u8868\nfor (String name : names) {\n    System.out.println(name);\n}<\/pre>\n<p>\u5728\u4e0a\u9762\u7684\u793a\u4f8b\u4e2d\uff0c<code>String::compareToIgnoreCase<\/code> \u662f\u4e00\u4e2a\u65b9\u6cd5\u5f15\u7528\uff0c\u5b83\u5f15\u7528\u4e86 <code>String<\/code> \u7c7b\u4e2d\u7684 <code>compareToIgnoreCase<\/code> \u5b9e\u4f8b\u65b9\u6cd5\u3002\u5f53\u5c06\u6b64\u65b9\u6cd5\u5f15\u7528\u4f20\u9012\u7ed9 <code>sort<\/code> \u65b9\u6cd5\u65f6\uff0c\u4f1a\u521b\u5efa\u4e0e <code>compareToIgnoreCase<\/code> \u65b9\u6cd5\u76f8\u540c\u7684\u884c\u4e3a\u7684\u6bd4\u8f83\u5668\u5bf9\u8c61\u3002<\/p>\n<p><strong>\u9759\u6001\u65b9\u6cd5\u5f15\u7528\uff1a<\/strong><\/p>\n<pre>\/\/ \u521b\u5efa\u4e00\u4e2a Function \u63a5\u53e3\uff0c\u7528\u4e8e\u5c06\u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a\u5927\u5199\nFunction&lt;String, String&gt; toUpperCase = String::toUpperCase;\n\n\/\/ \u4f7f\u7528\u65b9\u6cd5\u5f15\u7528\u5c06\u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a\u5927\u5199\nString upperCaseString = toUpperCase.apply(\"hello\");\n\n\/\/ \u8f93\u51fa\u5927\u5199\u5b57\u7b26\u4e32\nSystem.out.println(upperCaseString);<\/pre>\n<p>\u5728\u4e0a\u9762\u7684\u793a\u4f8b\u4e2d\uff0c<code>String::toUpperCase<\/code> \u662f\u4e00\u4e2a\u65b9\u6cd5\u5f15\u7528\uff0c\u5b83\u5f15\u7528\u4e86 <code>String<\/code> \u7c7b\u4e2d\u7684 <code>toUpperCase<\/code> \u9759\u6001\u65b9\u6cd5\u3002\u5f53\u5c06\u6b64\u65b9\u6cd5\u5f15\u7528\u4f20\u9012\u7ed9 <code>Function<\/code> \u63a5\u53e3\u65f6\uff0c\u4f1a\u521b\u5efa\u4e0e <code>toUpperCase<\/code> \u65b9\u6cd5\u76f8\u540c\u7684\u884c\u4e3a\u7684\u51fd\u6570\u5bf9\u8c61\u3002<\/p>\n<p><strong>\u5b9e\u6218\u6848\u4f8b<\/strong><\/p>\n<p>\u65b9\u6cd5\u5f15\u7528\u5728\u4ee5\u4e0b\u573a\u666f\u4e2d\u5f88\u6709\u7528\uff1a<\/p>\n<ul>\n<li><strong>\u51fd\u6570\u5f0f\u7f16\u7a0b\uff1a<\/strong>\u4f7f\u7528\u65b9\u6cd5\u5f15\u7528\u53ef\u4ee5\u589e\u5f3a\u51fd\u6570\u5f0f\u7f16\u7a0b\u98ce\u683c\uff0c\u4f7f\u5176\u66f4\u52a0\u7b80\u6d01\u548c\u6613\u4e8e\u7406\u89e3\u3002<\/li>\n<li><strong>\u4e8b\u4ef6\u5904\u7406\uff1a<\/strong>\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u65b9\u6cd5\u5f15\u7528\u4e3a GUI \u5143\u7d20\u6216\u5176\u4ed6\u4e8b\u4ef6\u6e90\u6ce8\u518c\u4e8b\u4ef6\u5904\u7406\u7a0b\u5e8f\u3002<\/li>\n<li><strong>lambdas \u7684\u66ff\u4ee3\u54c1\uff1a<\/strong>\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u65b9\u6cd5\u5f15\u7528\u53ef\u4ee5\u4f5c\u4e3a lambdas \u7684\u7b80\u5316\u66ff\u4ee3\u54c1\uff0c\u5c24\u5176\u662f\u5728\u6211\u4eec\u9700\u8981\u5f15\u7528\u5916\u90e8\u65b9\u6cd5\u65f6\u3002<\/li>\n<\/ul>\n<p><strong>\u4f18\u70b9<\/strong><\/p>\n<ul>\n<li>\u7b80\u6d01\u6027<\/li>\n<li>\u53ef\u8bfb\u6027<\/li>\n<li>\u6548\u7387\uff08\u65e0\u9700\u521b\u5efa\u533f\u540d\u7c7b\u6216 lambda \u8868\u8fbe\u5f0f\uff09<\/li>\n<\/ul>\n<p>\u901a\u8fc7\u7406\u89e3\u548c\u4f7f\u7528\u4f7f\u7528\u65b9\u6cd5\u5f15\u7528\u5b9a\u4e49 Java \u51fd\u6570\uff0c\u6211\u4eec\u53ef\u4ee5\u7f16\u5199\u66f4\u6e05\u6670\u3001\u66f4\u7b80\u6d01\u7684\u4ee3\u7801\uff0c\u5e76\u4e14\u66f4\u6709\u6548\u5730\u5229\u7528\u51fd\u6570\u5f0f\u7f16\u7a0b\u3002<\/p>\n<p>\u4eca\u5929\u5173\u4e8e\u300a\u5982\u4f55\u4f7f\u7528\u65b9\u6cd5\u5f15\u7528\u5b9a\u4e49 Java \u51fd\u6570\uff1f\u300b\u7684\u5185\u5bb9\u4ecb\u7ecd\u5c31\u5230\u6b64\u7ed3\u675f\uff0c\u5982\u679c\u6709\u4ec0\u4e48\u7591\u95ee\u6216\u8005\u5efa\u8bae\uff0c\u53ef\u4ee5\u5728\u516c\u4f17\u53f7\u4e0b\u591a\u591a\u56de\u590d\u4ea4\u6d41\uff1b\u6587\u4e2d\u82e5\u6709\u4e0d\u6b63\u4e4b\u5904\uff0c\u4e5f\u5e0c\u671b\u56de\u590d\u7559\u8a00\u4ee5\u544a\u77e5\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u4f55\u4f7f\u7528\u65b9\u6cd5\u5f15\u7528\u5b9a\u4e49 Java &#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4925],"tags":[],"class_list":["post-203029","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/203029","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=203029"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/203029\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=203029"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=203029"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=203029"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}