2 回答

TA貢獻(xiàn)1836條經(jīng)驗(yàn) 獲得超13個(gè)贊
Go 1.5 將添加一個(gè)可以在這里提供幫助的功能。(回顧 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
測(cè)試用例包括以下有趣的代碼:
v := MakeFunc(FuncOf([]Type{TypeOf(K(""))}, []Type{TypeOf(V(0))}, false), fn)
outs := v.Call([]Value{ValueOf(K("gopher"))})
- 2 回答
- 0 關(guān)注
- 203 瀏覽
添加回答
舉報(bào)