Standard library / reflect

reflect.Value.SetBool()

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

Formal Syntax & Structure

go syntaxgo
func (v Value) SetBool(x bool)

Parameters & Attributes

NameTypeDescription
xboolNew value; must satisfy the destination kind or assignability requirement.

Working Example

Example Snippetgo
package main
import (  "fmt"  "reflect")
func main() { var x bool; reflect.ValueOf(&x).Elem().SetBool(true); fmt.Println(x) }
Go Reference