Ok, I see. Thanks a lot. 在 2018年3月27日星期二 UTC+8上午2:11:47,[email protected]写道: > > With interface{} it has to be a type check at runtime: > https://play.golang.org/p/t2jip9E__F1 > > Matt > > On Monday, March 26, 2018 at 12:34:34 PM UTC-5, 刘焱 wrote: >> >> 'chan interface {}' dosen't work. >> >> package main >> >> import "fmt" >> >> type ChannelWrapper struct { >> Channel chan interface{} >> } >> >> func main() { >> x := make(chan int) >> y := ChannelWrapper { x } >> fmt.Println(y) >> } >> >> Build this will yield >> cannot use x (type chan int) as type chan interface {} in field value >> >> >> Cast x as follow: >> chan interface{} (x) >> >> Will yield >> cannot convert x (type chan int) to type chan interface {} >> >> >> >> 在 2018年3月24日星期六 UTC+8上午1:41:59,[email protected]写道: >>> >>> An empty interface var can hold any type, so you could have a chan >>> interface{} then use an interface type assertion when you read a value. >>> >>> Matt >> >>
-- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
