```go
package golang
import (
"fmt"
"testing"
)
func valType(v interface{}) {
switch v := v.(type) {
case *int:
fmt.Println("*int", v == nil)
case int:
fmt.Println("int", v)
}
}
func valType2(v interface{}) {
switch v := v.(type) {
case *int, *string:
fmt.Println("*int or *string", v == nil) // 为什么不为nil
case int:
fmt.Println("int", v)
}
}
func TestValType(t *testing.T) {
var v *int
valType(v)
valType2(v)
var s *string
valType2(s)
}
```
有疑问加站长微信联系(非本文作者)