On Fri, Nov 23, 2018 at 2:06 PM Youqi yu <yuyouqi101...@gmail.com> wrote:
>
> type T {
>  Name string
> }
> a := &T{Name:"test"}
> b :=&T{Name:"test"}
> *a == *b
> Hi, all, I am beginner at golang, I have a question that when compare struct 
> equality, I was told to use reflect.DeepEqual or make my own function. but 
> the result of above code is true. Does it mean struct a equals struct b?

Yes, they are equal. But how the equality is decided may not always be
what you want.
eg.

type T {
   Name string
   Child *T
}
a := &T{Name:"test", Child: &T{Name: "blah", Child: nil}}
b :=&T{Name:"test", Child: &T{Name: "blah", Child: nil}}
*a == *b // false
reflect.DeepEqual(a,b) //true

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to