I don't understand how go
compares anonymous structures. I am trying to understand this piece of code:
package main
import (
"fmt"
)
type foo struct {
bar string
}
func main() {
var x struct {
bar string
}
var y foo
fmt.Println(x == y) // this prints true
equals(x, y) // this prints false
}
func equals(a, b interface{}) {
fmt.Println(a == b)
}
Why does x == y
yields true
? They have a different type, so I would expect that they cannot be compared.
And, as they are equal, why casting them to interface{}
makes them unequal?