Я пытаюсь сравнить идентичность 2 карт
package main
import "fmt"
func main() {
a := map[int]map[int]int{1:{2:2}}
b := a[1]
c := a[1]
// I can't do this:
// if b == c
// because I get:
// invalid operation: b == c (map can only be compared to nil)
// but as far as I can tell, mutation works, meaning that the 2 maps might actually be identical
b[3] = 3
fmt.Println(c[3]) // so mutation works...
fmt.Printf("b as pointer::%p\n", b)
fmt.Printf("c as pointer::%p\n", c)
// ok, so maybe these are the pointers to the variables b and c... but still, those variables contain the references to the same map, so it's understandable that these are different, but then I can't compare b==c like this
fmt.Printf("&b::%p\n", &b)
fmt.Printf("&c::%p\n", &c)
fmt.Println(&b == &c)
}
, это дает следующий результат:
3
b as pointer::0x442280
c as pointer::0x442280
&b::0x40e130
&c::0x40e138
false
Что меня особенно смущает, так это то, что b as pointer::0x442280
иc as pointer::0x442280
кажется, имеют те же значения, что действительно подтвердило бы мое подозрение, что эти переменные так или иначе указывают на один и тот же диктат.
Так кто-нибудь знает, как я могу заставить себя сказать, что b
иc
"один и тот же объект"?