wk := make(map[string]interface{})
tc := make(chan int)
wk["ttc"] = tc
再从map中把tc取出来,不能正常的存取了
wk:=make(map[string]interface{})
tc := make(chan int)
wk["ttc"] = tc
#1
更多评论
需要进行类型断言的,示例代码
package main
import(
"fmt"
)
func main() {
wk := make(map[string]interface{})
tc := make(chan int)
wk["ttc"] = tc
channel := wk["ttc"].(chan int)
go getFromChannel(channel)
channel<-2
fmt.Println("done")
}
func getFromChannel(c chan int) {
fmt.Println(<-c)
}
输出:
2
done
#2