35. Go 语言中关于接口的三个"潜规则"
Hi,大家好,我是明哥。 在自己学习 Golang 的这段时间里,我写了详细的学习笔记放在我的个人微信公众号 《Go编程时光》,对于 Go 语言,我也算是个初学者,因此写的东西应该会比较适合刚接触的同学,如果你也是刚学习 Go 语言,不防关注一下,一起学习,一起成长。 我的在线博客: http://golang.iswbm.com 我的 Github:github.com/iswbm/GolangCodingTime 1. 对方法的调用限制 接口是一组固定的方法集,由于静态类型的限制,接口变量有时仅能调用其中特定的一些方法。 请看下面这段代码 package main import "fmt" type Phone interface { call() } type iPhone struct { name string } func (phone iPhone)call() { fmt.Println("Hello, iPhone.") } func (phone iPhone)send_wechat() { fmt.Println("Hello, Wechat.") } func main() { var phone Phone phone = iPhone{name:"ming's iphone"} phone.call() phone.send_wechat() }