golang 反射

golang 反射,第1张

概述package mainimport ( "fmt" "reflect")type Person struct{}func (p *Person) Run() { fmt.Println("person running")}func doit(object interface{}, method interface{}) { v := ref
package mainimport (	"fmt"	"reflect")type Person struct{}func (p *Person) Run() {	fmt.Println("person running")}func doit(object interface{},method interface{}) {	v := reflect.ValueOf(object)	f := reflect.ValueOf(method)	f.Call([]reflect.Value{v})}func main() {	p := new(Person)	doit(p,(*Person).Run)}
总结

以上是内存溢出为你收集整理的golang 反射全部内容,希望文章能够帮你解决golang 反射所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/langs/1292757.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-06-10
下一篇2022-06-10

发表评论

登录后才能评论

评论列表(0条)

    保存