Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
假设我在 Go 中有一个 chan:
var c = make(chan int)
如何使用以下方法发现它是一个频道:
var isChannel = reflect.ValueOf(c).Kind() == reflect.Chan
但有谁知道我如何确定频道的类型,在这种情况下int?
int
用于Elem获取通道类型:
Elem
var isChannel = reflect.ValueOf(c).Kind() == reflect.Chan channelType := reflect.ValueOf(c).Type().Elem()
对于一个int频道,channelType将是int.
channelType