1. 程式人生 > >Go——空接口與斷言

Go——空接口與斷言

println 斷言 接口 pri interface func student face main

斷言

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——空接口與斷言