蝴蝶不菲
package mainimport "fmt"func main() { i := 32 j := 32 fmt.Printf("%p is %p\n", &i, &i) fmt.Printf("%p is not %p\n", &i, &j)}输出:0xc000016100 is 0xc0000161000xc000016100 is not 0xc000016108游乐场:https://play.golang.org/p/nXAEJeImeXa然而,package mainimport "fmt"func main() { i := 32 j := 32 fmt.Printf("i %p is i %p; i == i %t\n", &i, &i, &i == &i) fmt.Printf("i %p is not j %p; i == j %t\n", &i, &j, &i == &j) fmt.Println() var v struct { i struct{} j struct{} } fmt.Printf("i %p is i %p; i == i %t\n", &v.i, &v.i, &v.i == &v.i) fmt.Printf("i %p is not j %p; i == j %t\n", &v.i, &v.j, &v.i == &v.j)}输出:i 0x40e020 is i 0x40e020; i == i truei 0x40e020 is not j 0x40e024; i == j falsei 0x1e52bc is i 0x1e52bc; i == i truei 0x1e52bc is not j 0x1e52bc; i == j true游乐场:https://play.golang.org/p/Wv814ZgPCul封装CMPimport "github.com/google/go-cmp/cmp"cmp 包确定值的相等性。该包旨在成为 Reflect.DeepEqual 的更强大、更安全的替代方案,用于比较两个值在语义上是否相等。