2022-06-28:以下golang代码输出什么?A:true;B:false;C:panic;D:编译失败。
代码语言:go复制package main
import "fmt"
func main() {
var p [100]int
var m interface{} = [...]int{99: 0}
fmt.Println(p == m)
}
答案2022-06-28:
答案选A。这道题以为选D,有点出乎意料。儿子属于老子,儿子们不属于老子们。只适合赋值,不适合比较。
A value x of non-interface type X and a value t of interface type T are comparable when values of type X are comparable and X implements T. They are equal if t's dynamic type is identical to X and t's dynamic value is equal to x. ——以上内容来自 https://go.dev/ref/spec#Operators