package main import ( "fmt" "reflect" ) type Person struct { Name string Age int } func main() { p := Person{Name: "Alice", Age: 30} v := reflect.ValueOf(p) // Set the Age field to 35 ageField := v.FieldByName("Age") ageField.SetInt(35) // Get the Name field nameField := v.FieldByName("Name") fmt.Printf("Name: %v\n", nameField.String()) }
package main import ( "fmt" "reflect" ) func main() { s := "42" v := reflect.ValueOf(s) // Convert to int i := int(v.Int()) fmt.Println(i) }Package Library: `reflect`