go类型断言

package main

import (
    "fmt"
)

func main() {
    var x interface{}
    x = "this is string"
    switch s := x.(type) {  // 等价于 s := x 且 switch type
    case string:
        fmt.Println(s, "string")
    }
}

你可能感兴趣的:(go类型断言)