一直弄不懂 .(type) 是啥,在 liteide 中输出 (1+1).(type),提示:
use of .(type) outside type switch
于是搜索到这个文章:
作者:翔云翔云
来源:CSDN 原文: 版权声明:本文为博主原创文章,转载请附上博文链接!package mainimport ( "fmt")func main() { CheckType("tow", 88, "three")}func CheckType(args ...interface{}) { for _,v := range args { switch v.(type) { case int: fmt.Println("type:int, value:", v) case string: fmt.Println("type:string, value:", v) default: fmt.Println("type:unkown,value:",v) } }}
2019/01/02补:
昨天看书看到这个叫类型断言