golang中的pair
package main import "fmt" type Reader interface { ReadBook() } type Writer interface { WriteBook() } // 具体类型 type Book struct {} func (b *Book) ReadBook() { fmt.Println("Read a Book") } func (b *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() // w: pair<type:, value:> var w Writer // w: pair<type:Book, value:book{}地址> // 此处的断言为什么会成功?因为w r 具体的type是一致的,所以会断言成功 w = r.(Writer) w.WriteBook() }