【发布时间】:2016-09-03 21:03:33
【问题描述】:
我能做到:
f, err := os.Create("file")
if err != nil {
....
}
by := bufio.NewWriter(f)
还有这个:
var _ io.Writer = &os.File{}
os.File 的包文档导致 this source file 确实包含 未导出 写入函数,但是当我尝试使用未导出函数实现接口时出现错误。
var _ Disease = &Scratch{} // *Scratch doesn't implement Disease have spread() want Spread()
type Disease interface {
Spread()
}
type Scratch struct {
....
}
func (s* Scratch) spread() {
....
}
我错过了什么?
更新:os.File did need cleaning up
【问题讨论】:
-
不确定您实际上在问什么,但
os.File实现了Write -
啊,它可能是bad link,因为该文件链接指向file_unix.go 而不是file.go,而且我没有仔细查看文件名
-
好吧,这不是一个坏链接。文件类型在 src/os 下的多个文件中重新定义,但导出的方法都在不同的文件中。现在出现的问题是如何允许在同一个包中重新定义?
-
有重新定义,因为只有一个定义该类型的文件将被包含在构建中。
-
那么他们为什么不将类型声明与所有导出的方法一起粘贴在一个文件中呢?