Standard library / reflect
reflect.Value.SetLen()
Changes the length of a settable slice within its capacity; it does not allocate. Expected stdout: '[0 0 0]\n'.
Formal Syntax & Structure
go syntaxgo
func (v Value) SetLen(n int)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| n | int | Requested size, length, capacity or growth amount, as specified by the operation. |
Working Example
Example Snippetgo
package main
import ( "fmt" "reflect")
func main() { s := make([]int, 1, 3); reflect.ValueOf(&s).Elem().SetLen(3); fmt.Println(s) }