x.(T)TxxTx.(type)switch
x.(type)
func checkType(args ...interface{}) {
for _, arg := range args {
switch arg.(type) {
case int:
fmt.Println(arg, "is an int value.")
case string:
fmt.Println(arg, "is a string value.")
case int64:
fmt.Println(arg, "is an int64 value.")
default:
fmt.Println(arg, "is an unknown type.")
}
}
}
x.(type)x.(T)xinterface{}
var num interface{} = 1 // num.(int) 可以执行
var num int = 1 // num.(int) 编译失败 invalid type assertion: num.(int) (non-interface type int on left)
x.(T)
v, ok := x.(int)
oktruexintv