How do I get the correct Type of the struct using the anonymous field (or superclass)?
I am trying to make this fish describe itself as a cod:
package main
import (
"fmt"
"reflect"
)
type Fish struct {
}
func (self *Fish) WhatAmI() string {
return reflect.TypeOf(self).String()
}
type Cod struct {
Fish
}
func main() {
c := new(Cod)
fmt.Println("I am a", c.WhatAmI())
}
The output I get is:
I am a *main.Fish
What I want is:
I am a *main.Cod