{"id":36215,"date":"2024-11-26T13:04:34","date_gmt":"2024-11-26T05:04:34","guid":{"rendered":"https:\/\/fwq.ai\/blog\/36215\/"},"modified":"2024-11-26T13:04:34","modified_gmt":"2024-11-26T05:04:34","slug":"%e5%a6%82%e4%bd%95%e5%9c%a8%e4%b8%80%e4%b8%aa%e6%98%a0%e5%b0%84%ef%bc%88map%ef%bc%89%e4%b8%ad%e5%ad%98%e5%82%a8%e4%b8%8d%e5%90%8c%e7%b1%bb%e7%9a%84%e5%a4%9a%e4%b8%aa-getter-%e6%96%b9%e6%b3%95%e5%bc%95","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/36215\/","title":{"rendered":"\u5982\u4f55\u5728\u4e00\u4e2a\u6620\u5c04\uff08Map\uff09\u4e2d\u5b58\u50a8\u4e0d\u540c\u7c7b\u7684\u591a\u4e2a getter \u65b9\u6cd5\u5f15\u7528\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173103249311032.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u5728\u4e00\u4e2a\u6620\u5c04\uff08Map\uff09\u4e2d\u5b58\u50a8\u4e0d\u540c\u7c7b\u7684\u591a\u4e2a getter \u65b9\u6cd5\u5f15\u7528\uff1f\u63d2\u56fe\" alt=\"\u5982\u4f55\u5728\u4e00\u4e2a\u6620\u5c04\uff08Map\uff09\u4e2d\u5b58\u50a8\u4e0d\u540c\u7c7b\u7684\u591a\u4e2a getter \u65b9\u6cd5\u5f15\u7528\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u58f0\u660e\u5bb9\u7eb3\u65b9\u6cd5\u5f15\u7528\u7684\u6620\u5c04\uff08Map\uff09<\/strong><\/p>\n<p>\u5982\u4f55\u5c06\u4e0d\u540c\u7c7b\u7684\u591a\u4e2a\u65b9\u6cd5\u5f15\u7528\u5b58\u50a8\u5728\u4e00\u4e2a\u6620\u5c04\uff08Map\uff09\u4e2d\uff1f\u8fd9\u4e9b\u65b9\u6cd5\u90fd\u662f getter \u65b9\u6cd5\uff0c\u4f46\u8fd4\u56de\u7c7b\u578b\u4e0d\u540c\uff0c\u4f8b\u5982 User::getUsername\u3001Group::getName \u548c Post::getId\u3002<\/p>\n<p>\u89e3\u51b3\u65b9\u6cd5\uff1a<\/p>\n<p>\u4f7f\u7528 IDEA \u7684\u4ee3\u7801\u63d0\u793a\u529f\u80fd\uff0c\u5177\u4f53\u6b65\u9aa4\u5982\u4e0b\uff1a<\/p>\n<ol>\n<li>\u5728\u4e00\u884c\u65b0\u4ee3\u7801\u4e2d\u8f93\u5165 Arrays.asList(getUsername, getId)\u3002<\/li>\n<li>\u5728\u5176\u540e\u8f93\u5165 \u201c.var\u201d \u5e76\u6309\u56de\u8f66\u952e\uff0cIDEA \u5c06\u81ea\u52a8\u63d0\u793a\u5217\u8868\u7684\u7c7b\u578b\u548c\u53d8\u91cf\u540d\u3002\u63d0\u793a\u7684\u7c7b\u578b\u4e3a List extends Function , ?&gt;&gt;\u3002<\/li>\n<li>\u6620\u5c04\u53ef\u4ee5\u4f7f\u7528\u7c7b\u4f3c\u7684\u58f0\u660e\uff0c\u5c06\u6620\u5c04\u7c7b\u578b\u58f0\u660e\u4e3a Map  &gt;\u3002  <\/li>\n<li>\u5c06\u65b9\u6cd5\u5f15\u7528\u653e\u5165\u6620\u5c04\u9700\u8981\u7c7b\u578b\u8f6c\u6362\uff0c\u4f8b\u5982\uff0c\u5c06 Group::getId \u653e\u5165\u6620\u5c04\u4e2d\uff1amap.put(&#8220;id&#8221;, (Function  ) Group::getId)\u3002  <\/li>\n<\/ol>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u5728\u4e00\u4e2a\u6620\u5c04\uff08Map\uff09\u4e2d\u5b58\u50a8\u4e0d\u540c\u7c7b\u7684\u591a\u4e2a getter \u65b9\u6cd5\u5f15\u7528\uff1f\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>\u58f0\u660e\u5bb9\u7eb3\u65b9\u6cd5\u5f15\u7528\u7684\u6620\u5c04\uff08Map\uff09 \u5982\u4f55\u5c06\u4e0d\u540c\u7c7b\u7684\u591a\u4e2a\u65b9\u6cd5\u5f15\u7528\u5b58\u50a8\u5728\u4e00\u4e2a\u6620\u5c04\uff08Map\uff09\u4e2d\uff1f\u8fd9\u4e9b\u65b9\u6cd5\u90fd\u662f getter \u65b9\u6cd5\uff0c\u4f46\u8fd4\u56de\u7c7b\u578b\u4e0d\u540c\uff0c\u4f8b\u5982 User::getUsername\u3001Group::getName \u548c Post::getId\u3002 \u89e3\u51b3\u65b9\u6cd5\uff1a \u4f7f\u7528 IDEA \u7684\u4ee3\u7801\u63d0\u793a\u529f\u80fd\uff0c\u5177\u4f53\u6b65\u9aa4\u5982\u4e0b\uff1a \u5728\u4e00\u884c\u65b0\u4ee3\u7801\u4e2d\u8f93\u5165 Arrays.asList(getUsername, getId)\u3002 \u5728\u5176\u540e\u8f93\u5165 \u201c.var\u201d \u5e76\u6309\u56de\u8f66\u952e\uff0cIDEA \u5c06\u81ea\u52a8\u63d0\u793a\u5217\u8868\u7684\u7c7b\u578b\u548c\u53d8\u91cf\u540d\u3002\u63d0\u793a\u7684\u7c7b\u578b\u4e3a List extends Function , ?&gt;&gt;\u3002 \u6620\u5c04\u53ef\u4ee5\u4f7f\u7528\u7c7b\u4f3c\u7684\u58f0\u660e\uff0c\u5c06\u6620\u5c04\u7c7b\u578b\u58f0\u660e\u4e3a Map &gt;\u3002 \u5c06\u65b9\u6cd5\u5f15\u7528\u653e\u5165\u6620\u5c04\u9700\u8981\u7c7b\u578b\u8f6c\u6362\uff0c\u4f8b\u5982\uff0c\u5c06 Group::getId \u653e\u5165\u6620\u5c04\u4e2d\uff1amap.put(&#8220;id&#8221;, (Function ) Group::getId)\u3002 \u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u5728\u4e00\u4e2a\u6620\u5c04\uff08Map\uff09\u4e2d\u5b58\u50a8\u4e0d\u540c\u7c7b\u7684\u591a\u4e2a getter \u65b9\u6cd5\u5f15\u7528\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/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-36215","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/36215","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=36215"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/36215\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=36215"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=36215"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=36215"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}