search
LoginSignup
1

More than 5 years have passed since last update.

posted at

Organization

Go言語:メソッドの引数の型を調べる方法

main.go
package main

import (
    "log"
    "reflect"
)

type Foo struct {}
func (this *Foo) DoSomething(param0 string, param1 int, param2 interface{}) {}

func main() {
    foo := &Foo{}
    methodType := reflect.ValueOf(foo.DoSomething).Type()
    log.Printf("param0: %#v", methodType.In(0).String())
    log.Printf("param1: %#v", methodType.In(1).String())
    log.Printf("param2: %#v", methodType.In(2).String())
}

出力結果

2014/01/07 21:54:40 param0: "string"
2014/01/07 21:54:40 param1: "int"
2014/01/07 21:54:40 param2: "interface {}"

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
What you can do with signing up
1