Standard library / reflect

reflect.Value.SetBytes()

Change a settable []byte value through its kind-specific setter. Wrong kinds or non-settable values panic; numeric conversions may narrow. Expected stdout: 'go\n'.

Formal Syntax & Structure

go syntaxgo
func (v Value) SetBytes(x []byte)

Parameters & Attributes

NameTypeDescription
x[]byteNew value; must satisfy the destination kind or assignability requirement.

Working Example

Example Snippetgo
package main
import (  "fmt"  "reflect")
func main() { var x []byte; reflect.ValueOf(&x).Elem().SetBytes([]byte("go")); fmt.Println(string(x)) }
Go Reference