Package Mainimport ("FMT" "reflect") Type Astruct{}func (A) Test () {fmt. Println ("gooooo reflect call empty Param method")}func (A) Testwithparam (APstringBpstring) {fmt. Println ("gooooo reflect call with Param method:", AP, BP)} Func Main () {vara a f:=reflect. ValueOf (a)//Null parameter when method calls a sequence numberF.method (0). Call (Nil)//Gooooo Method//Null parameter when method calls two method names inch: = Make ([]reflect. Value,0) F.methodbyname ("Test"). Call (inch)//Gooooo Method//Multi-parameter invocationParray: = []string{"Hello","reflect"} INP:=Make ([]reflect. Value, Len (parray)) forK, param: =range Parray {inp[k]=reflect. ValueOf (param)} f.methodbyname ("Testwithparam"). Call (INP)}//Print//gooooo reflect call empty Param method//gooooo reflect call empty Param method//gooooo reflect call with Param Method:hello reflect
Go reflect Call method