Go——空接口与断言

Posted cnloop

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Go——空接口与断言相关的知识,希望对你有一定的参考价值。

断言

func main() {
    s := student{1, "wqx", ‘m‘, 15, "hefei"}
    m := make(map[int]interface{})
    m[0] = s
    v, ok := m[0].(student) // 断言
    if ok {
        fmt.Println(v.age)
    }
}

反射

以上是关于Go——空接口与断言的主要内容,如果未能解决你的问题,请参考以下文章