方法一:用Printf判斷
package main
import (
"fmt"
)
func main() {
v1 := "123456"
v2 := 12
fmt.Printf("v1 type:%T\n", v1)
fmt.Printf("v2 type:%T\n", v2)
}
輸出內容:
v1 type:string
v2 type:int
方法二:reflect
package main
import (
"fmt"
"reflect"
)
func main() {
v1 := "123456"
v2 := 12
// reflect
fmt.Println("v1 type:", reflect.TypeOf(v1))
fmt.Println("v2 type:", reflect.TypeOf(v2))
}
輸出內容:
v1 type:string
v2 type:int