【发布时间】:2018-08-10 07:01:20
【问题描述】:
如何将接收者作为类型声明函数?
我以为我可以做到以下几点,但它抱怨语法错误:
type myFunc func(s *State) (blah Blah) err
func main() {
b := &Blah{}
s := &State{}
var f = myF
s.f(b)
}
func (s *State) myF(blah Blah) err {
...
}
【问题讨论】:
-
别以为你能做到。
-
使用接口。
标签: go type-alias