{"id":124696,"date":"2020-06-14T11:10:13","date_gmt":"2020-06-14T03:10:13","guid":{"rendered":"http:\/\/4563.org\/?p=124696"},"modified":"2020-06-14T11:10:13","modified_gmt":"2020-06-14T03:10:13","slug":"%e6%96%b0%e6%89%8b%e6%b1%82%e6%95%99%e4%b8%80%e4%b8%aa%e7%b1%bb%e5%9e%8b%e6%96%ad%e8%a8%80%e7%9a%84%e9%97%ae%e9%a2%98","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=124696","title":{"rendered":"\u65b0\u624b\u6c42\u6559\u4e00\u4e2a\u7c7b\u578b\u65ad\u8a00\u7684\u95ee\u9898"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  \u65b0\u624b\u6c42\u6559\u4e00\u4e2a\u7c7b\u578b\u65ad\u8a00\u7684\u95ee\u9898               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : inori <\/span>  <span><i><\/i> 5<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\">                        \u6211\u7406\u89e3 go \u65ad\u8a00\u8fd4\u56de\u7684\u5e94\u8be5\u662f\u5bf9\u5e94\u7c7b\u578b\u7684\u5bf9\u8c61\uff0c\u6bd4\u5982\u8bf4<br \/>package main<\/p>\n<p>import (<br \/> &#8220;fmt&#8221;<br \/>)<\/p>\n<p>func findType(i interface{}) {<br \/> switch x := i.(type) {<br \/> case int:<br \/> fmt.Println(x, &#8220;is int&#8221;)<br \/> case string:<br \/> fmt.Println(x, &#8220;is string&#8221;)<br \/> case nil:<br \/> fmt.Println(x, &#8220;is nil&#8221;)<br \/> default:<br \/> fmt.Println(x, &#8220;not type matched&#8221;)<br \/> }<br \/>}<\/p>\n<p>func main() {<br \/> findType(10) \/\/ int<br \/> findType(&#8220;hello&#8221;) \/\/ string<\/p>\n<p> var k interface{} \/\/ nil<br \/> findType(k)<\/p>\n<p> findType(10.23) \/\/float64<br \/>}<\/p>\n<p>\u8fd9\u91cc x \u5e94\u8be5\u662f\u5177\u4f53\u7c7b\u578b\u7684\u503c 10, &#8220;hello&#8221;\u4e4b\u7c7b\u7684\uff0c\u4e3a\u4ec0\u4e48\u53ef\u4ee5\u548c int string \u8fd9\u4e9b case \u5339\u914d\u5462\uff1f      <\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>4<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"2176778\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : Vegetable <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u6211\u53bb\u8fd8\u80fd\u8fd9\u4e48\u5199&#8230;\u6211\u4ee5\u524d\u90fd\u662f\u5224\u65ad\u597d\u4e86\u518d\u8f6c\u4e00\u6b21                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"2176779\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : whoami9894 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             val.(type)\u662f\u7c7b\u578b\u65ad\u8a00\u7684\u7279\u6b8a\u8bed\u6cd5\uff0c\u548c val.(int)\u4ec0\u4e48\u7684\u4e0d\u4e00\u6837                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"2176780\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : stevenbipt <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             .(type)\u4f1a\u8fd4\u56de interface{}\u7684\u7c7b\u578b,\u7136\u540e\u4f7f\u7528 switch \u5339\u914d\u7c7b\u578b\u7684 case,\u8fd9\u91cc\u7684 case \u751a\u81f3\u53ef\u4ee5\u662f\u63a5\u53e3\u7c7b\u578b,\u7b97\u662f go \u7684\u4e00\u4e2a\u4e13\u7528\u8bed\u6cd5\u4e86                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"2176781\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : tidyoux <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u7b80\u5355\u8bf4\uff0c\u53ef\u4ee5\u8ba4\u4e3a i.(type) \u8fd4\u56de\u4e86 i \u7684\u503c\u548c\u7c7b\u578b\uff0cswitch \u6bd4\u8f83\u7528\u7684\u662f\u7c7b\u578b\uff0c\u503c\u662f\u65b9\u4fbf\u7a0b\u5e8f\u5458\u7528\u7684\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>\u65b0\u624b\u6c42\u6559\u4e00\u4e2a\u7c7b\u578b\u65ad\u8a00\u7684\u95ee\u9898 \u8cc7\u6df1\u5927&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/124696"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=124696"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/124696\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=124696"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=124696"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=124696"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}