Created
October 9, 2013 02:49
-
-
Save kwmt/6895428 to your computer and use it in GitHub Desktop.
リフレクションを使って関数をコールする。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "fmt" | |
| "reflect" | |
| ) | |
| func f(n uint, m int) uint{ | |
| return n+ uint(m) | |
| } | |
| func main() { | |
| fv := reflect.ValueOf(f) | |
| arg1 := reflect.ValueOf(uint(100)) //reflect.Value | |
| arg2 := reflect.ValueOf(200) //reflect.Value | |
| //関数コール | |
| result := fv.Call([]reflect.Value{arg1, arg2}) //[]reflect.Value ←戻り値も複数返せる為、スライスとなっている | |
| fmt.Println(result[0].Uint()) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment