.(type)判断类型只能在switch当中使用
package main
import(
"fmt"
)
func main(){
into := 0
checkType(into)
}
func checkType(into interface{}){
switch into.(type){
case int:
fmt.Println("int") // int
case bool:
fmt.Println("bool")
case float64:
fmt.Println("float64")
default:
fmt.Println("wrong")
}
//fmt.Println(into.(type)) //报错: use of .(type) outside type switch
}