I’m trying to find out what type was passed into an interface. The interface is implemented by two struct
types.
type T interface {
hello()
}
type foo struct{}
func (f *foo) hello() {}
type boo struct{}
func (b *boo) hello() {}
func main() {
abc(&foo{})
abc(&boo{})
}
func abc(t T) {
switch t {
case &foo{}:
fmt.Println("foo")
case &boo{}:
fmt.Println("boo")
default:
fmt.Println("NOTHING")
}
}
This always prints out "NOTHING"
and "NOTHING"
Could someone please clarify what I’m missing?
Link to full code: Go Playground - The Go Programming Language