1. 首页
  2. 主题
  3. Go问与答

断言类型可以是结构体?

yinwhm12 · · 3478 次点击
就是通过 e.(type) 得出case中的那个结构体,可以实现?
`e` 是 `interface` 就行
#1
更多评论
真的?你能给个例子?我新手,拜托了!
#2
```go package main import "fmt" func main() { type Person struct { Name string } var i interface{} = Person{"golang"} switch i.(type) { case Person: fmt.Println(i.(Person).Name) default: } } ```
#3

用户登录

没有账号?注册

今日阅读排行

    加载中

一周阅读排行

    加载中