关于接口“所有已知实现”的文档

在学习 Go 几个月后,我才发现通过实现函数来os.File实现io.Reader接口Read(b []byte) (n int, err error)。这允许我使用缓冲阅读器通过执行以下操作来读取文件:


f, err := os.Open("myfile.txt")

bufReader := bufio.NewReader(f)

除非我错过它,否则在接口的 Go 文档中似乎没有“所有已知的实现类”,就像在 Java 接口文档中找到的那样。


有什么方法可以识别在 Go 中实现接口的类型吗?


HUX布斯
浏览 191回答 3
3回答

精慕HU

为了你vim的吸毒者在那里,VIM-GO使用支持先进的代码分析:GoImplements,:GoCallees,:GoChannelPeers,:GoReferrers等Oracle命令。例如,如果我有一个如下所示的Calculator接口和实现:type Arithmetic interface{  add(float64, float64) float64 }type Calculator struct{}func (c *calculator) add(o1, o2 float64) float64 {  // ... stuff}然后:GoImplements用我的光标在 vim 中运行type Arithmetic interface将产生如下结果:calculator.go|8 col 6| interface type Arithmeticcalculator.go|3 col 6| is implemented by pointer type *calculator现在,如果我将光标移动到该type Calculator struct{}行并运行:GoImplements,我将得到如下结果:calculator.go|3 col 6| pointer type *calculatorcalculator.go|8 col 6| implements Arithmetic注意:如果您收到“未知命令”错误,请:GoInstallBinaries在重试之前先尝试执行。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Go