{"id":42288,"date":"2024-12-01T14:37:05","date_gmt":"2024-12-01T06:37:05","guid":{"rendered":"https:\/\/fwq.ai\/blog\/42288\/"},"modified":"2024-12-01T14:37:05","modified_gmt":"2024-12-01T06:37:05","slug":"%e6%8e%a5%e5%8f%a3%e6%96%b9%e6%b3%95%e5%bc%95%e7%94%a8%e7%9b%b8%e5%90%8c%e7%9a%84%e6%8e%a5%e5%8f%a3%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/42288\/","title":{"rendered":"\u63a5\u53e3\u65b9\u6cd5\u5f15\u7528\u76f8\u540c\u7684\u63a5\u53e3\uff1f"},"content":{"rendered":"<p><b><\/b> <\/p>\n<p>\u5f53\u524d\u4f4d\u7f6e\uff1a <span>&gt;<\/span>  <span>&gt;<\/span>  <span>&gt;<\/span>  <span>&gt;<\/span> <span>\u63a5\u53e3\u65b9\u6cd5\u5f15\u7528\u76f8\u540c\u7684\u63a5\u53e3\uff1f<\/span><\/p>\n<h1>\u63a5\u53e3\u65b9\u6cd5\u5f15\u7528\u76f8\u540c\u7684\u63a5\u53e3\uff1f<\/h1>\n<p><span>\u6765\u6e90\uff1astackoverflow<\/span><br \/>\n<span>2024-04-23 13:15:30<\/span><br \/>\n<span><i><\/i>0\u6d4f\u89c8<\/span><br \/>\n<span style=\"cursor: pointer\"><i><\/i>\u6536\u85cf<\/span> <\/p>\n<p>\u7c73\u4e91\u4eca\u5929\u5c06\u7ed9\u5927\u5bb6\u5e26\u6765<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300a\u63a5\u53e3\u65b9\u6cd5\u5f15\u7528\u76f8\u540c\u7684\u63a5\u53e3\uff1f\u300b<\/span>\uff0c\u611f\u5174\u8da3\u7684\u670b\u53cb\u8bf7\u7ee7\u7eed\u770b\u4e0b\u53bb\u5427\uff01\u4ee5\u4e0b\u5185\u5bb9\u5c06\u4f1a\u6d89\u53ca\u5230<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\u7b49\u7b49\u77e5\u8bc6\u70b9\uff0c\u5982\u679c\u4f60\u662f\u6b63\u5728\u5b66\u4e60<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">Golang<\/span>\u6216\u8005\u5df2\u7ecf\u662f\u5927\u4f6c\u7ea7\u522b\u4e86\uff0c\u90fd\u975e\u5e38\u6b22\u8fce\u4e5f\u5e0c\u671b\u5927\u5bb6\u90fd\u80fd\u7ed9\u6211\u5efa\u8bae\u8bc4\u8bba\u54c8~\u5e0c\u671b\u80fd\u5e2e\u52a9\u5230\u5927\u5bb6\uff01<\/p>\n<p> \u95ee\u9898\u5185\u5bb9<br \/>\n <\/p>\n<p>\u6211\u662f\u4e00\u540djava\u7a0b\u5e8f\u5458\uff0c\u6211\u73b0\u5728\u6b63\u5728\u5b66\u4e60go\u3002 \u6211\u5c1d\u8bd5\u7f16\u5199\u4e00\u4e2a\u540d\u4e3a vo \u7684\u81ea\u5d4c\u5957\u63a5\u53e3\uff0c\u4ee5\u53ca\u4e00\u4e2a\u540d\u4e3a score \u7684 vo \u5b9e\u73b0\uff0c \u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre>type vo interface {\n        merge(v vo) vo\n}\n\ntype score int\n\nfunc (this score) merge(s score) score {\n    return score(this + s)\n}\n\nfunc testthepkg(t *testing.t) {\n    s := score(5)\n    var v vo = s \/\/compile error\n}<\/pre>\n<p>\u8be6\u7ec6\u7f16\u8bd1\u9519\u8bef\u662f\uff1a<\/p>\n<pre>cannot use s (variable of type Score) as Vo value in variable declaration: Score does not implement Vo (wrong type for method Merge)\n        have Merge(s Score) Score\n        want Merge(v Vo) VocompilerInvalidIfaceAssign<\/pre>\n<p>\u5982\u4f55\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\uff1f \u8c22\u8c22\uff01<\/p>\n<p> <\/p>\n<h2>\u6b63\u786e\u7b54\u6848<\/h2>\n<p> <\/p>\n<pre>func (this Score) Merge(s Vo) Vo {\n    if typeAssersion, ok := s.(Score); ok {\n        return Score(this + typeAssersion)\n    }\n    \/\/log err or the `Vo` interface should return (Vo,error)\n    return nil\n}<\/pre>\n<p>\u7406\u8bba\u8981\u638c\u63e1\uff0c\u5b9e\u64cd\u4e0d\u80fd\u843d\uff01\u4ee5\u4e0a\u5173\u4e8e\u300a\u63a5\u53e3\u65b9\u6cd5\u5f15\u7528\u76f8\u540c\u7684\u63a5\u53e3\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\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\u5427\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5f53\u524d\u4f4d\u7f6e\uff1a &gt; &gt; &gt; &gt; \u63a5\u53e3\u65b9\u6cd5\u5f15\u7528\u76f8\u540c\u7684\u63a5\u53e3\uff1f \u63a5\u53e3\u65b9\u6cd5\u5f15\u7528\u76f8\u540c\u7684\u63a5\u53e3\uff1f \u6765\u6e90\uff1astackoverflow 2024-04-23 13:15:30 0\u6d4f\u89c8 \u6536\u85cf \u7c73\u4e91\u4eca\u5929\u5c06\u7ed9\u5927\u5bb6\u5e26\u6765\u300a\u63a5\u53e3\u65b9\u6cd5\u5f15\u7528\u76f8\u540c\u7684\u63a5\u53e3\uff1f\u300b\uff0c\u611f\u5174\u8da3\u7684\u670b\u53cb\u8bf7\u7ee7\u7eed\u770b\u4e0b\u53bb\u5427\uff01\u4ee5\u4e0b\u5185\u5bb9\u5c06\u4f1a\u6d89\u53ca\u5230\u7b49\u7b49\u77e5\u8bc6\u70b9\uff0c\u5982\u679c\u4f60\u662f\u6b63\u5728\u5b66\u4e60Golang\u6216\u8005\u5df2\u7ecf\u662f\u5927\u4f6c\u7ea7\u522b\u4e86\uff0c\u90fd\u975e\u5e38\u6b22\u8fce\u4e5f\u5e0c\u671b\u5927\u5bb6\u90fd\u80fd\u7ed9\u6211\u5efa\u8bae\u8bc4\u8bba\u54c8~\u5e0c\u671b\u80fd\u5e2e\u52a9\u5230\u5927\u5bb6\uff01 \u95ee\u9898\u5185\u5bb9 \u6211\u662f\u4e00\u540djava\u7a0b\u5e8f\u5458\uff0c\u6211\u73b0\u5728\u6b63\u5728\u5b66\u4e60go\u3002 \u6211\u5c1d\u8bd5\u7f16\u5199\u4e00\u4e2a\u540d\u4e3a vo \u7684\u81ea\u5d4c\u5957\u63a5\u53e3\uff0c\u4ee5\u53ca\u4e00\u4e2a\u540d\u4e3a score \u7684 vo \u5b9e\u73b0\uff0c \u4ee3\u7801\u5982\u4e0b\uff1a type vo interface { merge(v vo) vo } type score int func (this score) merge(s score) score { return score(this + s) } func testthepkg(t *testing.t) { s := score(5) var v [&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-42288","post","type-post","status-publish","format-standard","hentry","category-docker"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/42288","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=42288"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/42288\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=42288"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=42288"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=42288"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}