package main import ( "fmt" ) var v = "1, 2, 3" func main() { v := []int{1, 2, 3} if v != nil { var v = 123 fmt.Printf("%v ", v) fmt.Printf("v type:%T ", v) } }
输出:
123
v type:int
package main import ( "fmt" "reflect" ) var v = "1, 2, 3" func main() { v := []int{1, 2, 3} if v != nil { var v = 123 fmt.Printf("%v ", v) fmt.Println("v type:", reflect.TypeOf(v)) } }
输出:
123
v type:int