dtnwm4807
2015-08-10 13:04
浏览 260
已采纳

“ <-chan”和“ chan”作为函数返回类型有什么区别?

Golang newbie here.

Is there a functional difference between

func randomNumberGenerator() <-chan int {

and

func randomNumberGenerator() chan int {

I've tried using both and they seem to work fine for me.

I've seen the former used by Rob Pike (one of Go creators) in his Go Concurrency Patterns talk at Google IO 2012. I've also seen it used in Go's official website. Why add 2 extra characters ("<-") when you can omit it? I've tried looking for the difference on the web, but couldn't find it.

2条回答 默认 最新

相关推荐 更多相似问题