switch v := v.(type) 求解

DonWang · · 2116 次点击
case后面是多个类型,就会把v转成interface么? 分开写貌似就行
#9
更多评论
#### 输出结果 ```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