最佳答案
我正在尝试一些 Go 对象实现。但是写入字符串而不是文件或类似文件的对象。我认为 bytes.Buffer
会工作,因为它实现 Write(p []byte)
。然而,当我尝试这样做时:
import "bufio"
import "bytes"
func main() {
var b bytes.Buffer
foo := bufio.NewWriter(b)
}
我得到以下错误:
cannot use b (type bytes.Buffer) as type io.Writer in function argument:
bytes.Buffer does not implement io.Writer (Write method has pointer receiver)
我很困惑,因为它清楚地实现了接口。我如何解决这个错误?