DeepEqual

Explain why the printed output is false?Modify line A to assure the printed output really equals to equality of the values of x and y.

  1. package main
  2. import (
  3. "fmt"
  4. )
  5. type S struct {
  6. a, b, c string
  7. }
  8. func main() {
  9. x := interface{}(&S{"a", "b", "c"})
  10. y := interface{}(&S{"a", "b", "c"})
  11. fmt.Println(x == y) //A
  12. }

Answer

  1. package main
  2. import (
  3. "fmt"
  4. "reflect"
  5. )
  6. type S struct {
  7. a, b, c string
  8. }
  9. func main() {
  10. x := interface{}(&S{"a", "b", "c"})
  11. y := interface{}(&S{"a", "b", "c"})
  12. fmt.Println(reflect.DeepEqual(x, y))
  13. }