[英]Go - Interface containing slice wont compile
type MyType interface {
MyStringSlice []string
}
What is wrong with this? 这有什么问题?
It works well as a struct as in: 它可以很好地用作以下结构:
type MyType struct {
MyStringSlice []string
}
but compiles with the following error when set as interface: 但设置为接口时会编译,并显示以下错误:
syntax error: unexpected [, expecting (
An interface can only hold methods or other interfaces. 一个接口只能保存方法或其他接口。 Have a look at the Language Specification . 看一下语言规范 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.