假设我们有这样的代码:
package main
import "fmt"
type Parent struct{}
func (p Parent) WhoCalledMe() string {
// return the name of instance who called this method, Parent or Child
}
type Child struct {
Parent
}
func main() {
child := Child{}
parent := Parent{}
fmt.Println(child.WhoCalledMe()) // return Child
fmt.Println(parent.WhoCalledMe()) // return Parent
}
是否可以获取调用WhoCalledMe
方法的实例的名称或类型?