我收到一個錯誤: undefined reflect.MakeFunc .. 為什么會這樣?package mainimport ( "fmt" "reflect")func main() { swap := func(in []reflect.Value) []reflect.Value { return []reflect.Value{in[1], in[0]} } makeSwap := func(fptr interface{}) { fn := reflect.ValueOf(fptr).Elem() fn.Set(reflect.MakeFunc(fn.Type(), swap)) } var intSwap func(int, int) (int, int) makeSwap(&intSwap) fmt.Println(intSwap(0, 1)) var floatSwap func(float64, float64) (float64, float64) makeSwap(&floatSwap) fmt.Println(floatSwap(2.72, 3.14))}
Go-Lang 中reflect.MakeFunc 的功能
慕工程0101907
2021-06-08 17:40:53