3
为何可以这样传递参数
source link: https://www.v2ex.com/t/848435
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
初学,有个疑惑的地方,例如
file, err := os.Open("/path/to/file.txt")
scanner := bufio.NewScanner(file)
这里 file 获传入 bufio.NewScanner ,但是文档写的是
func Open(name string) (*File, error)
func NewScanner(r io.Reader) *Scanner
这里接受的是参数是 r io.Reader ,为何 file 可以传过去,是否是因为 file 实现了接口导致的,我在文档里面也没有看到有提及,如果是这样在哪里可以看到哪些参数实现了哪些接口呢,不能要用的时候一个个去断言吧?
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK