Standard library / reflect

reflect.Value.CallSlice()

Invokes a variadic function using a slice as the final argument, equivalent to passing that slice with ellipsis. Expected stdout: '2\n'.

Formal Syntax & Structure

go syntaxgo
func (v Value) CallSlice(in []Value) []Value

Parameters & Attributes

NameTypeDescription
in[]ValueOrdered reflected argument values; CallSlice requires a final slice argument.

Return Value

[]Value

Invokes a variadic function using a slice as the final argument, equivalent to passing that slice with ellipsis.

Working Example

Example Snippetgo
package main
import (  "fmt"  "reflect")
func main() {  f := reflect.ValueOf(func(xs ...int) int { return len(xs) })  fmt.Println(f.CallSlice([]reflect.Value{reflect.ValueOf([]int{1, 2})})[0].Int())}
Go Reference