美文网首页
x.(type) x 必须位interface类型

x.(type) x 必须位interface类型

作者: anthonydan | 来源:发表于2020-03-20 11:57 被阅读0次

x.(type) x 必须位interface类型
package main

import "fmt"

func main() {
i := GetValue()
switch i.(type) {
case int:
fmt.Println("int")
case string:
fmt.Println("string")
case interface{}:
fmt.Println("interface")
default:
fmt.Println("unknown")
}
}
func GetValue() int {
return 1
}

相关文章

网友评论

      本文标题:x.(type) x 必须位interface类型

      本文链接:https://www.haomeiwen.com/subject/sffjyhtx.html