switch v := v.(type) 求解

DonWang · · 2205 次点击
#### 输出结果 ```shell *int true *int or *string false *int or *string false ```
#1
更多评论
case 后面跟多个类型时,只要其中一个类型匹配, 会直接将v赋值给k,类似执行k:=v ```go switch k := v.(type) { case *int, *string: fmt.Println("*int or *string", k == nil) case int: fmt.Println("int", k) } ```
#2
是的,但是赋值完之后k应该为nil呀,参考valType
#3