有没有任何解决方案可以强制结构具有特定属性(在接口中定义)?
或者在接口中定义一个属性(属性,字段)?
正如我所看到的,接口总是接受方法而不是属性?( https://gobyexample.com/interfaces)
type geo interface {
PrintType()
typ string//not function , but field
}
type circle struct {
typ string
}
func (c circle) PrintType() {
fmt.Println(c.typ)
}
谢谢
茅侃侃
相关分类