type MyFunc func(int, int) int func calc3(x, y int) int { return x + y } func execTime(call MyFunc) MyFunc { return func(int, int) int { start := time.Now() r := call(x, y) fmt.Println("程序执行耗时", time.Since(start)) return r } } func TestFuncLearn(t *testing.T) { wrapper := execTime(calc3) r := wrapper(1, 2) fmt.Println("计算结果为", r) fmt.Println("计算结果 2 为", calc3(1, 2)) } 执行结果..
=== RUN TesFuncLearn 程序执行耗时 125ns 计算结果为 5 计算结果 2 为 3 --- PASS: TestFuncLearn (0.00s) PASS 请问一下问什么执行结果是 5 呢,debug 进去,x=2 ,y=3,人傻了
