package main import "fmt" type IReader interface { Read(file string) []byte } type IWriter interface { Write(file string, data []byte) } // 接口组合, 这些默认就继承了Reader和Writer中的抽象方法 type IReadWriter interface { IReader IWriter } type ReadWriter struct { } func (rw *ReadWriter) Read(file string) []byte { return nil } func (rw *ReadWriter) Write(file string, data []byte) { } func main() { rw := new(ReadWriter) var iRw IReadWriter = rw // ok fmt.Println(iRw) }
时间: 2024-11-08 22:18:08