type Test struct { }
I knew this may be the way to check empty struct by (Test{}) == test
. However, it seems not working for the struct which only contains one boolean field. Considering this example:
package main
import "fmt"
type Test struct {
Foo bool
}
func main() {
empty := Test{}
test1 := Test{Foo: true}
test2 := Test{Foo: false}
fmt.Println(Test{} == test1) //False yay
fmt.Println(Test{} == test2) //True oh no ...
fmt.Println(Test{} == empty) //True yay
}
Basically, == thinks the struct containing false
field is same to empty struct.
Is there a better way to check the empty struct or am I missing something here ?
Also, you may wonder why only have one field in struct, well, because the struct is in development phase, it may have more fields later on.