switch v := v.(type) 求解

DonWang · · 2267 次点击
还看不懂么,多值类型的赋值,只能是 interface{},所以v2是 interface{},自然不等于null
#7
更多评论
#### 输出结果 ```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