{"id":858,"date":"2024-11-07T14:47:42","date_gmt":"2024-11-07T06:47:42","guid":{"rendered":"https:\/\/fwq.ai\/blog\/858\/"},"modified":"2024-11-07T14:47:42","modified_gmt":"2024-11-07T06:47:42","slug":"go-%e8%af%ad%e8%a8%80-interface-%e5%92%8c-map-%e7%9a%84%e9%99%b7%e9%98%b1%ef%bc%9a%e5%a6%82%e4%bd%95%e7%90%86%e8%a7%a3-mapstringint-%e5%92%8c-mapstringint%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/858\/","title":{"rendered":"Go \u8bed\u8a00 Interface \u548c map \u7684\u9677\u9631\uff1a\u5982\u4f55\u7406\u89e3 map[string]int{} \u548c map[string]int\uff1f"},"content":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1055\" src=\"https:\/\/fwq.ai\/blog\/wp-content\/uploads\/2024\/11\/173016416866660.jpg\" width=\"800\" height=\"320\" srcset=\"https:\/\/fwq.ai\/blog\/wp-content\/uploads\/2024\/11\/173016416866660.jpg 800w, https:\/\/fwq.ai\/blog\/wp-content\/uploads\/2024\/11\/173016416866660-300x120.jpg 300w, https:\/\/fwq.ai\/blog\/wp-content\/uploads\/2024\/11\/173016416866660-768x307.jpg 768w, https:\/\/fwq.ai\/blog\/wp-content\/uploads\/2024\/11\/173016416866660-670x268.jpg 670w\" sizes=\"auto, (max-width: 800px) 100vw, 800px\" title=\"Go \u8bed\u8a00 Interface \u548c map \u7684\u9677\u9631\uff1a\u5982\u4f55\u7406\u89e3 map[string]int{} \u548c map[string]int\uff1f\u63d2\u56fe\" alt=\"Go \u8bed\u8a00 Interface \u548c map \u7684\u9677\u9631\uff1a\u5982\u4f55\u7406\u89e3 map[string]int{} \u548c map[string]int\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>Go \u8bed\u8a00\u7684 Interface \u4e2d\u7684\u7591\u95ee<\/strong><\/p>\n<p>\u5728 Go \u8bed\u8a00\u4e2d\uff0cinterface \u662f\u4e00\u4e2a\u5f3a\u5927\u7684\u7279\u6027\uff0c\u53ef\u4ee5\u5f88\u5bb9\u6613\u5730\u5b9e\u73b0\u591a\u6001\u884c\u4e3a\u3002\u7136\u800c\uff0c\u4f7f\u7528\u65f6\u4e5f\u6709\u4e00\u4e9b\u9700\u8981\u6ce8\u610f\u7684\u9677\u9631\u3002<\/p>\n<p><strong>map[string]int{} \u4e2d\u7684 int{}<\/strong><\/p>\n<p>\u5728\u5b9a\u4e49\u6620\u5c04 map \u65f6\uff0c\u4f8b\u5982 map[string]int{}\uff0c\u65b9\u62ec\u53f7\u5185\u7684 int{} \u662f\u4e00\u4e2a\u8bed\u6cd5\u7cd6\uff0c\u8868\u793a\u521d\u59cb\u5316\u4e00\u4e2a\u7a7a\u6620\u5c04\u3002\u5b83\u4e0e map[string]int \u7684\u533a\u522b\u5728\u4e8e\uff0c\u540e\u8005\u53ea\u662f\u5b9a\u4e49\u4e86\u6620\u5c04\u7684\u7c7b\u578b\uff0c\u800c\u524d\u8005\u4f1a\u7acb\u5373\u521b\u5efa\u4e00\u4e2a\u7a7a\u7684\u6620\u5c04\u3002<\/p>\n<p><strong>\u6bd4\u8f83 map[string]int<\/strong><\/p>\n<p>\u5728 Go \u8bed\u8a00\u4e2d\uff0cmap \u662f\u4e00\u4e2a\u590d\u6742\u7c7b\u578b\uff0c\u8fd9\u610f\u5473\u7740\u5b83\u662f\u4e00\u4e2a\u7531\u5e95\u5c42\u6570\u636e\u7ed3\u6784\u652f\u6301\u7684\u81ea\u5b9a\u4e49\u7c7b\u578b\u3002\u56e0\u6b64\uff0cGo \u8bed\u8a00\u5e76\u6ca1\u6709\u4e3a map \u5b9e\u73b0\u7c7b\u578b\u6bd4\u8f83\u7684\u64cd\u4f5c\u3002\u5f53\u5c1d\u8bd5\u6bd4\u8f83\u4e24\u4e2a map \u65f6\uff0c\u4f60\u5c06\u6536\u5230 runtime error: comparing uncomparable type \u9519\u8bef\u3002<\/p>\n<p>\u56e0\u6b64\uff0c\u4ee3\u7801\u4e2d\u7684 println(t1==t2) \u884c\u4f1a\u62a5\u9519\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fGo \u8bed\u8a00 Interface \u548c map \u7684\u9677\u9631\uff1a\u5982\u4f55\u7406\u89e3 map[string]int{} \u548c map[string]int\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>Go \u8bed\u8a00\u7684 Interface \u4e2d\u7684\u7591\u95ee \u5728 Go \u8bed\u8a00\u4e2d\uff0cinterface \u662f\u4e00\u4e2a\u5f3a\u5927\u7684\u7279\u6027\uff0c\u53ef\u4ee5\u5f88\u5bb9\u6613\u5730\u5b9e\u73b0\u591a\u6001\u884c\u4e3a\u3002\u7136\u800c\uff0c\u4f7f\u7528\u65f6\u4e5f\u6709\u4e00\u4e9b\u9700\u8981\u6ce8\u610f\u7684\u9677\u9631\u3002 map[string]int{} \u4e2d\u7684 int{} \u5728\u5b9a\u4e49\u6620\u5c04 map \u65f6\uff0c\u4f8b\u5982 map[string]int{}\uff0c\u65b9\u62ec\u53f7\u5185\u7684 int{} \u662f\u4e00\u4e2a\u8bed\u6cd5\u7cd6\uff0c\u8868\u793a\u521d\u59cb\u5316\u4e00\u4e2a\u7a7a\u6620\u5c04\u3002\u5b83\u4e0e map[string]int \u7684\u533a\u522b\u5728\u4e8e\uff0c\u540e\u8005\u53ea\u662f\u5b9a\u4e49\u4e86\u6620\u5c04\u7684\u7c7b\u578b\uff0c\u800c\u524d\u8005\u4f1a\u7acb\u5373\u521b\u5efa\u4e00\u4e2a\u7a7a\u7684\u6620\u5c04\u3002 \u6bd4\u8f83 map[string]int \u5728 Go \u8bed\u8a00\u4e2d\uff0cmap \u662f\u4e00\u4e2a\u590d\u6742\u7c7b\u578b\uff0c\u8fd9\u610f\u5473\u7740\u5b83\u662f\u4e00\u4e2a\u7531\u5e95\u5c42\u6570\u636e\u7ed3\u6784\u652f\u6301\u7684\u81ea\u5b9a\u4e49\u7c7b\u578b\u3002\u56e0\u6b64\uff0cGo \u8bed\u8a00\u5e76\u6ca1\u6709\u4e3a map \u5b9e\u73b0\u7c7b\u578b\u6bd4\u8f83\u7684\u64cd\u4f5c\u3002\u5f53\u5c1d\u8bd5\u6bd4\u8f83\u4e24\u4e2a map \u65f6\uff0c\u4f60\u5c06\u6536\u5230 runtime error: comparing uncomparable type \u9519\u8bef\u3002 \u56e0\u6b64\uff0c\u4ee3\u7801\u4e2d\u7684 println(t1==t2) \u884c\u4f1a\u62a5\u9519\u3002 \u4ee5\u4e0a\u5c31\u662fGo \u8bed\u8a00 Interface \u548c map \u7684\u9677\u9631\uff1a\u5982\u4f55\u7406\u89e3 map[string]int{} \u548c map[string]int\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-858","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/858","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=858"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/858\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=858"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=858"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=858"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}