Standard library / reflect
reflect.Value.SetCap()
Changes the capacity of a settable slice to a value between its length and current capacity. Expected stdout: '2 3\n'.
Formal Syntax & Structure
go syntaxgo
func (v Value) SetCap(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, 2, 5) reflect.ValueOf(&s).Elem().SetCap(3) fmt.Println(len(s), cap(s))}