Skip to content

reflect value.Interface not copy for struct #1156

Closed
@visualfc

Description

@visualfc

demo

package main

import (
	"fmt"
	"reflect"
)

type student struct {
	name string
}

func main() {
	a := []student{student{"A"}, student{"B"}, student{"C"}}
	v := reflect.ValueOf(a)
	i := v.Index(0).Interface()
	a[0] = student{"X"}
	fmt.Println(a, i)
}

go run main.go

[{X} {B} {C}] {A}

gopherjs run main.go

[{X} {B} {C}] {X}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions