golang接口的这个用法,我到还真是百思不得其解,望解惑

ddxx11223 · 2017-10-12 12:27:09 · 1202 次点击

谢谢回答,应该是“任何类型只要它实现了某个interface A的所有方法”吧

#4
更多评论

叫做:类型断言,可以理解为类型转换。

#1

规范里面是这里定义的:

“An interface type specifies a method set called its interface. A variable of interface type can store a value of any type with a method set that is any superset of the interface”

这里的any也包括其它interface类型, 任何类型只要它实现了某个interface A的所有接口,这个类型的变量就可以转换为A类型

#2