例如,
type FooService interface {
Foo1(x int) int
Foo2(x string) string
}
我想做的是获取列表["Foo1", "Foo2"]
使用运行时反射。
尝试这个:
t := reflect.TypeOf((*FooService)(nil)).Elem()
var s []string
for i := 0; i < t.NumMethod(); i++ {
s = append(s, t.Method(i).Name)
}
游乐场示例
获取接口类型的reflect.Type 是棘手的部分。看如何获取接口的reflect.Type?以获得解释。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)