why global variable a1 is not equal to local variable a2, but a2 is equal to a3 and a4
It is so confusing for me, a1, a2, a3 are all evaluated by calling the method getInterface, but when compare them, it get different result.
Thank you, everybody who see the question.
import "fmt"
var a1 aInterface = getInterface()
type aInterface interface {
fun1()
}
type aInterfaceImpl struct{}
func (p *aInterfaceImpl) fun1() {
return
}
func getInterface() aInterface {
return new(aInterfaceImpl)
}
func main() {
var a2 aInterface = getInterface()
var a3 aInterface = getInterface()
var a4 aInterface = new(aInterfaceImpl)
fmt.Printf("a1 == a2, %+v\n", a1 == a2) // a1 == a2, false
fmt.Printf("a2 == a3, %+v\n", a2 == a3) // a2 == a3, true
fmt.Printf("a2 == a4, %+v\n", a2 == a4) // a2 == a4, true
}