我正在尝试理解界面概念。以下是我的测试代码:
package main
import "fmt"
//interface
type InterfaceA interface {
A() string
}
//interface
type InterfaceB interface {
A() string
}
//user defined type structure
type structure struct {
a string
}
//implementing A(), but which A() ?
func (strt structure) A() string {
return strt.a
}
func main() {
fmt.Println("Start")
variable := structure{"hello"}
fmt.Println(variable.A())
}
根据文档,我知道没有像其他语言那样明确提及“实现”。但是当我调用variable.A()我的类型structure使用哪个接口时?InterfaceA还是InterfaceB?另外,我真的正确地实现了接口吗?
UYOU
蛊毒传说
相关分类