How can I get the shadowed methods via reflection?
In the code below I'm using MethodByName to get method Test()
on type B
, but I would like to get the shadowed method Test()
from b.A
as well, so I can call both of them.
package main
import (
"fmt"
"reflect"
)
type A struct {}
type B struct {
A
}
func (self *A) Test() {
fmt.Println("I'm A")
}
func (self *B) Test() {
fmt.Println("I'm B")
}
func main() {
b := &B{}
b.Test() // This one shadows b.A.Test()
b.A.Test() // but its ok to call like this
// via reflection
val := reflect.ValueOf(b)
val.MethodByName("Test").Call([]reflect.Value{})
}
Code available here: http://play.golang.org/p/6YPLy2dmMb