package main
import "fmt"
func main() {
a := '1'
b := '1'
var c int64 = 2
d := int64(c)
e := int64(d) - 1
if a == b{
fmt.Println("a==b")
}
if c == d {
fmt.Println("c==d")
}
if e == 1 {
fmt.Println("e==1")
}
//if ct := c.(type);int64 == ct {
// fmt.Println("c is int64")
//}//./main.go:21:15: use of .(type) outside type switch
//./main.go:21:23: type int64 is not an expression
// switch ct := c.(type){
// case int64:
// fmt.Println("c is int64")
// case int32:
// fmt.Println("c is int32")
// }//./main.go:24:5: cannot type switch on non-interface value c (type int64)
var f interface{}
f = c
switch ft := f.(type){
case int64:
fmt.Println("ft", ft)
fmt.Println("c is int64")
case int32:
fmt.Println("c is int32")
}
fmt.Println("Hello world!")
//Output:
//a==b
//c==d
//e==1
//ft 2
//c is int64
//Hello world!
}
go switch 判断 type 匹配变量类型
最新推荐文章于 2024-05-16 15:53:38 发布