在做树的递归遍历按层遍历的代码的时候遇到一个问题就是这样
var ff = func (int) {
ff()
}
上面的代码编译不过去。
查找资料是这么讲的:
We've written >100k lines of Go code and it has come up maybe once. That kind of frequency doesn't suggest that a language change is warranted.
意思就是说,在实际编码中遇到需要这种特性的几率很小很小,所以没有必要直接在语言层面去支持,如果偶然遇到就使用替代方案吧
当然也是有替代方案的
type funcType func(int)
var f funcType
f = func(i int) {
f(i)
}