📌  相关文章
📜  type switch golang - Go 编程语言 - Go 编程语言代码示例

📅  最后修改于: 2022-03-11 14:45:01.067000             🧑  作者: Mango

代码示例2
var x interface{} = "foo"

switch v := x.(type) {
case nil:
    fmt.Println("x is nil")            // here v has type interface{}
case int: 
    fmt.Println("x is", v)             // here v has type int
case bool, string:
    fmt.Println("x is bool or string") // here v has type interface{}
default:
    fmt.Println("type unknown")        // here v has type interface{}
}