{"id":40850,"date":"2024-12-01T12:58:22","date_gmt":"2024-12-01T04:58:22","guid":{"rendered":"https:\/\/fwq.ai\/blog\/40850\/"},"modified":"2024-12-01T12:58:22","modified_gmt":"2024-12-01T04:58:22","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-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/40850\/","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>\u54c8\u55bd\uff01\u5927\u5bb6\u597d\uff0c\u5f88\u9ad8\u5174\u53c8\u89c1\u9762\u4e86\uff0c\u6211\u662fgolang\u5b66\u4e60\u7f51\u7684\u4e00\u540d\u4f5c\u8005\uff0c\u4eca\u5929\u7531\u6211\u7ed9\u5927\u5bb6\u5e26\u6765\u4e00\u7bc7<br \/>\n<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300aGo \u8bed\u8a00 Interface \u548c map \u7684\u9677\u9631\uff1a\u5982\u4f55\u7406\u89e3 map[string]int{} \u548c map[string]int\uff1f\u300b<\/span>\uff0c\u672c\u6587\u4e3b\u8981\u4f1a\u8bb2\u5230<br \/>\n<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\u7b49\u7b49\u77e5\u8bc6\u70b9\uff0c\u5e0c\u671b\u5927\u5bb6\u4e00\u8d77\u5b66\u4e60\u8fdb\u6b65\uff0c\u4e5f\u6b22\u8fce\u5927\u5bb6\u5173\u6ce8\u3001\u70b9\u8d5e\u3001\u6536\u85cf\u3001\u8f6c\u53d1! \u4e0b\u9762\u5c31\u4e00\u8d77\u6765\u770b\u770b\u5427\uff01,<br \/>\n<img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241030\/17302624696721b5c58bcfb.jpg\" class=\"aligncenter\" 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\" \/>,<br \/>\n<strong>Go \u8bed\u8a00\u7684 Interface \u4e2d\u7684\u7591\u95ee<\/strong>,\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,<br \/>\n<strong>map[string]int{} \u4e2d\u7684 int{}<\/strong>,\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,<br \/>\n<strong>\u6bd4\u8f83 map[string]int<\/strong>,\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,\u7406\u8bba\u8981\u638c\u63e1\uff0c\u5b9e\u64cd\u4e0d\u80fd\u843d\uff01\u4ee5\u4e0a\u5173\u4e8e\u300aGo \u8bed\u8a00 Interface \u548c map \u7684\u9677\u9631\uff1a\u5982\u4f55\u7406\u89e3 map[string]int{} \u548c map[string]int\uff1f\u300b\u7684\u8be6\u7ec6\u4ecb\u7ecd\uff0c\u5927\u5bb6\u90fd\u638c\u63e1\u4e86\u5427\uff01\u5982\u679c\u60f3\u8981\u7ee7\u7eed\u63d0\u5347\u81ea\u5df1\u7684\u80fd\u529b\uff0c\u90a3\u4e48\u5c31\u6765\u5173\u6ce8golang\u5b66\u4e60\u7f51\u516c\u4f17\u53f7\u5427\uff01,Go \u8bed\u8a00\u7684 Interface \u4e2d\u7684\u7591\u95ee,\u54c8\u55bd\uff01\u5927\u5bb6\u597d\uff0c\u5f88\u9ad8\u5174\u53c8\u89c1\u9762\u4e86\uff0c\u6211\u662fgolang\u5b66\u4e60\u7f51\u7684\u4e00\u540d\u4f5c\u8005\uff0c\u4eca\u5929\u7531\u6211\u7ed9\u5927\u5bb6\u5e26\u6765\u4e00\u7bc7<br \/>\n<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300aGo \u8bed\u8a00 Interface \u548c map \u7684\u9677\u9631\uff1a\u5982\u4f55\u7406\u89e3 map[string]int{} \u548c map[string]int\uff1f\u300b<\/span>\uff0c\u672c\u6587\u4e3b\u8981\u4f1a\u8bb2\u5230<br \/>\n<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\u7b49\u7b49\u77e5\u8bc6\u70b9\uff0c\u5e0c\u671b\u5927\u5bb6\u4e00\u8d77\u5b66\u4e60\u8fdb\u6b65\uff0c\u4e5f\u6b22\u8fce\u5927\u5bb6\u5173\u6ce8\u3001\u70b9\u8d5e\u3001\u6536\u85cf\u3001\u8f6c\u53d1! \u4e0b\u9762\u5c31\u4e00\u8d77\u6765\u770b\u770b\u5427\uff01,<br \/>\n<b><\/b> <\/p>\n<p>\u5f53\u524d\u4f4d\u7f6e\uff1a <span>&gt;<\/span>  <span>&gt;<\/span>  <span>&gt;<\/span>  <span>&gt;<\/span> <span>Go \u8bed\u8a00 Interface \u548c map \u7684\u9677\u9631\uff1a\u5982\u4f55\u7406\u89e3 map[string]int{} \u548c map[string]int\uff1f<\/span><\/p>\n<h1>Go \u8bed\u8a00 Interface \u548c map \u7684\u9677\u9631\uff1a\u5982\u4f55\u7406\u89e3 map[string]int{} \u548c map[string]int\uff1f<\/h1>\n<p><span>2024-10-30 12:28:05<\/span><br \/>\n<span><i><\/i>0\u6d4f\u89c8<\/span><br \/>\n<span style=\"cursor: pointer\"><i><\/i>\u6536\u85cf<\/span> <\/p>\n<p>\u54c8\u55bd\uff01\u5927\u5bb6\u597d\uff0c\u5f88\u9ad8\u5174\u53c8\u89c1\u9762\u4e86\uff0c\u6211\u662fgolang\u5b66\u4e60\u7f51\u7684\u4e00\u540d\u4f5c\u8005\uff0c\u4eca\u5929\u7531\u6211\u7ed9\u5927\u5bb6\u5e26\u6765\u4e00\u7bc7<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300aGo \u8bed\u8a00 Interface \u548c map \u7684\u9677\u9631\uff1a\u5982\u4f55\u7406\u89e3 map[string]int{} \u548c map[string]int\uff1f\u300b<\/span>\uff0c\u672c\u6587\u4e3b\u8981\u4f1a\u8bb2\u5230<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\u7b49\u7b49\u77e5\u8bc6\u70b9\uff0c\u5e0c\u671b\u5927\u5bb6\u4e00\u8d77\u5b66\u4e60\u8fdb\u6b65\uff0c\u4e5f\u6b22\u8fce\u5927\u5bb6\u5173\u6ce8\u3001\u70b9\u8d5e\u3001\u6536\u85cf\u3001\u8f6c\u53d1! \u4e0b\u9762\u5c31\u4e00\u8d77\u6765\u770b\u770b\u5427\uff01<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241030\/17302624696721b5c58bcfb.jpg\" class=\"aligncenter\" 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>\u7406\u8bba\u8981\u638c\u63e1\uff0c\u5b9e\u64cd\u4e0d\u80fd\u843d\uff01\u4ee5\u4e0a\u5173\u4e8e\u300aGo \u8bed\u8a00 Interface \u548c map \u7684\u9677\u9631\uff1a\u5982\u4f55\u7406\u89e3 map[string]int{} \u548c map[string]int\uff1f\u300b\u7684\u8be6\u7ec6\u4ecb\u7ecd\uff0c\u5927\u5bb6\u90fd\u638c\u63e1\u4e86\u5427\uff01\u5982\u679c\u60f3\u8981\u7ee7\u7eed\u63d0\u5347\u81ea\u5df1\u7684\u80fd\u529b\uff0c\u90a3\u4e48\u5c31\u6765\u5173\u6ce8golang\u5b66\u4e60\u7f51\u516c\u4f17\u53f7\u5427\uff01<\/p>\n<dl>\n<dt>\n <\/dt>\n<dd>\n   \u5982\u4f55\u5728\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u4e2d\u5b9e\u73b0\u8d85\u51fa\u7701\u7565\u53f7\uff1f\n <\/dd>\n<\/dl>\n<dl>\n<dt>\n <\/dt>\n<dd>\n   \u4e3a\u4ec0\u4e48 CSS \u6837\u5f0f\u4e0b\u4e24\u5f20\u56fe\u7247\u4e0d\u663e\u793a\uff0cleft \u6837\u5f0f\u6ca1\u6709\u5bbd\u5ea6\uff0c\u867d\u7136\u7236\u5143\u7d20\u6709\u5bbd\u5ea6\uff0c\u4f46\u53ea\u6709 30% \u5b50\u5143\u7d20\u6709\u5bbd\u5ea6\uff1f\n <\/dd>\n<\/dl>\n","protected":false},"excerpt":{"rendered":"<p>\u54c8\u55bd\uff01\u5927\u5bb6\u597d\uff0c\u5f88\u9ad8\u5174\u53c8\u89c1\u9762\u4e86\uff0c\u6211\u662fgolang\u5b66\u4e60\u7f51\u7684\u4e00\u540d\u4f5c\u8005\uff0c\u4eca\u5929\u7531\u6211\u7ed9\u5927\u5bb6\u5e26\u6765\u4e00\u7bc7 \u300aGo \u8bed\u8a00 Interface \u548c map \u7684\u9677\u9631\uff1a\u5982\u4f55\u7406\u89e3 map[string]int{} \u548c map[string]int\uff1f\u300b\uff0c\u672c\u6587\u4e3b\u8981\u4f1a\u8bb2\u5230 \u7b49\u7b49\u77e5\u8bc6\u70b9\uff0c\u5e0c\u671b\u5927\u5bb6\u4e00\u8d77\u5b66\u4e60\u8fdb\u6b65\uff0c\u4e5f\u6b22\u8fce\u5927\u5bb6\u5173\u6ce8\u3001\u70b9\u8d5e\u3001\u6536\u85cf\u3001\u8f6c\u53d1! \u4e0b\u9762\u5c31\u4e00\u8d77\u6765\u770b\u770b\u5427\uff01, , 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,\u7406\u8bba\u8981\u638c\u63e1\uff0c\u5b9e\u64cd\u4e0d\u80fd\u843d\uff01\u4ee5\u4e0a\u5173\u4e8e\u300aGo \u8bed\u8a00 Interface \u548c map \u7684\u9677\u9631\uff1a\u5982\u4f55\u7406\u89e3 map[string]int{} \u548c [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[17],"tags":[],"class_list":["post-40850","post","type-post","status-publish","format-standard","hentry","category-docker"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/40850","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=40850"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/40850\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=40850"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=40850"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=40850"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}