Golang 通过字符串调用方法

package mainimport (fmtreflect)type Student struct {}func (s *Student) Listen() {fmt.Println(listen)}func main() {student := Student{}value := reflect.ValueOf(student)f := value.MethodByName...

package main

import (
	"fmt"
	"reflect"
)

type Student struct {
}

func (s *Student) Listen() {
	fmt.Println("listen")
}

func main() {
	student := Student{}
	value := reflect.ValueOf(&student)
	f := value.MethodByName("Listen")
	f.Call([]reflect.Value{})
}

本文标题为:Golang 通过字符串调用方法