刚学 go 语言,请大家帮忙看看我下面这段代码问题是什么

26次阅读

共计 428 个字符,预计需要花费 2 分钟才能阅读完成。

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   TestFuncLearn
程序执行耗时 125ns
计算结果为 5
计算结果 2 为 3
--- PASS: TestFuncLearn (0.00s)
PASS

请问一下问什么执行结果是 5 呢,debug 进去,x=2,y=3, 人傻了

正文完
 0