Quick actions

cmd+k|ctrl+k

Navigation

Languages

Reflection / Slice / Essential Go

Snippet info

Language

Go

Visibility

public

Author

kkowalczyk

Created

2019-03-26T10:17:03Z

Updated

2019-03-26T10:17:03Z

package main

import (
	"fmt"
	"reflect"
)

func main() {
	typ := reflect.SliceOf(reflect.TypeOf("example"))
	// create slice with capacity 10 and length 1
	rv := reflect.MakeSlice(typ, 1, 10)
	rv.Index(0).SetString("foo")

	a := rv.Interface().([]string)
	fmt.Printf("a: %#v\n", a)
}
INFO