Standard library / reflect

reflect.Method

Metadata for a method. For concrete types Func includes the receiver as the first argument; for interface types Func is invalid. Expected stdout: 'Name 1\n'.

Formal Syntax & Structure

go syntaxgo
type Method struct {  Name string
  PkgPath string
  Type  Type  Func  Value  Index int}

Working Example

Example Snippetgo
package main
import (  "fmt"  "reflect")
type Item struct{}
func (Item) Name() string { return "demo" }func main()               { m, _ := reflect.TypeOf(Item{}).MethodByName("Name"); fmt.Println(m.Name, m.Type.NumIn()) }
Go Reference