2 回答

TA贡献1836条经验 获得超13个赞
Go 1.5 将添加一个可以在这里提供帮助的功能。(回顾 1996 年,由Dave ( )提交 e1c1fa2)okdave
// FuncOf returns the function type with the given argument and result types.
// For example if k represents int and e represents string,
// FuncOf([]Type{k}, []Type{e}, false) represents func(int) string.
//
// The variadic argument controls whether the function is variadic. FuncOf
// panics if the in[len(in)-1] does not represent a slice and variadic is
// true.
func FuncOf(in, out []Type, variadic bool) Type
测试用例包括以下有趣的代码:
v := MakeFunc(FuncOf([]Type{TypeOf(K(""))}, []Type{TypeOf(V(0))}, false), fn)
outs := v.Call([]Value{ValueOf(K("gopher"))})
- 2 回答
- 0 关注
- 176 浏览
添加回答
举报