Standard library / reflect
reflect.Value.Method()
Returns a bound exported method for a concrete receiver by method index; the receiver is already bound. Expected stdout: '6\n'.
Formal Syntax & Structure
go syntaxgo
func (v Value) Method(i int) ValueParameters & Attributes
| Name | Type | Description |
|---|---|---|
| i | int | Zero-based index, or the input interface value for TypeOf and ValueOf. |
Return Value
Value
Returns a bound exported method for a concrete receiver by method index; the receiver is already bound.
Working Example
Example Snippetgo
package main
import ( "fmt" "reflect")
type Counter int
func (c Counter) Double() int { return int(c) * 2 }func main() { v := reflect.ValueOf(Counter(3)); fmt.Println(v.Method(0).Call(nil)[0].Int()) }