如何获取函数的返回值长度,效果类似如下:
func Foo() (int, int){
...
}
func Bar() (int, float, bool, string, error){
...
}
n1 := getReturnLength(Foo) // shall be 2
n2 := getReturnLength(Bar) // shall be 5
Run Code Online (Sandbox Code Playgroud)
我该如何实现getReturnLength功能或平等的功能?
在 go 中,当 key 不存在时,map 的值是零值。我在下面有一个简短的代码片段: 操场
package main
import (
"sync"
)
func main() {
var mm map[int]sync.Mutex
var m sync.Mutex
mm[1].Lock() // not work due to cannot call pointer method on mm[1] and cannot take the address of mm[1]
m.Lock() // work normal
}
Run Code Online (Sandbox Code Playgroud)
mm[1]和m上面有什么区别?我用reflect来检查,但看不出它们之间的区别。关于导致差异的任何线索?