2 举个例子
package main
import "fmt"
type Reader interface {
ReadBook()
}
type Writer interface {
WriteBook()
}
//具体类型
type Book struct {
}
func (this *Book) ReadBook() {
fmt.Println("Read a Book")
}
func (this *Book) WriteBook() {
fmt.Println("Write a Book")
}
func main() {
//b: pair<type:Book,value:book>
b := &Book{}
//r: pair<type:,value>
var r Reader
//r:pair<type:Book,value:book{}地址>
r = b
r.ReadBook()
var w Writer
//r:pair<type:Book,value:book()地址>
w=r.(Writer) //此处w r具体的type是一致的
w.WriteBook()
}