Standard library / reflect
reflect.Value.Call()
Invokes a reflected function with assignable arguments and returns a slice of result Values. Variadic arguments can be supplied individually. Expected stdout: '6\n'.
Formal Syntax & Structure
go syntaxgo
func (v Value) Call(in []Value) []ValueParameters & Attributes
| Name | Type | Description |
|---|---|---|
| in | []Value | Ordered reflected argument values; CallSlice requires a final slice argument. |
Return Value
[]Value
Invokes a reflected function with assignable arguments and returns a slice of result Values.
Working Example
Example Snippetgo
package main
import ( "fmt" "reflect")
func main() { f := reflect.ValueOf(func(x int) int { return x + 1 }) r := f.Call([]reflect.Value{reflect.ValueOf(5)}) fmt.Println(r[0].Int())}